Skip to content

Instantly share code, notes, and snippets.

@blondie7575
Created March 17, 2013 21:21
Show Gist options
  • Save blondie7575/5183707 to your computer and use it in GitHub Desktop.
Save blondie7575/5183707 to your computer and use it in GitHub Desktop.
; Name: romImage.s
; Author: Quinn Dunki
; Copyright: ©2012 Quinn Dunki
; License: All Rights Reserved
;
; 6052 code for Veronica's main system ROM
; For details, see http://www.quinndunki.com/blondihacks
;
; Zero Page:
; $00..$01: Subroutine parameter 1
; $10..$11: Scratch
;
; GPU commands:
;
CLEARSCR = $01
PLOTCHAR = $02
PLOTSTR = $03
FONTFGCLR = $04
FONTBGCLR = $05
CURSORXPOS = $06
CURSORYPOS = $07
.macro GPUCMD cmdByte,paramByte
lda #cmdByte
sta $efff
lda #paramByte
sta $efff
.endmacro
;
; Function calling
;
.macro CALL16 subroutine,param16
lda #<param16
sta $00
lda #>param16
sta $01
jsr subroutine
.endmacro
;
; Constants:
;
GPUREG = $efff ; GPU command and status register
RAMSTART_LO = $00 ; First valid RAM location, after stack
RAMSTART_HI = $02
RAMEND_LO = $01 ; Last valid RAM location +1
RAMEND_HI = $e0
TESTVALUE = $42 ; Bit pattern written and read to test RAM locations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Veronica main system ROM
;
; Boot entry point: $F000
;
.org $f000
jsr delay ; Give GPU time to boot and achieve VGA lock
jsr delay
jsr delay
ramCheck:
GPUCMD CLEARSCR,$00 ; Show introduction text
GPUCMD FONTFGCLR,$3f
GPUCMD FONTBGCLR,$00
CALL16 printStr,prompt
GPUCMD CURSORXPOS,$00
GPUCMD CURSORYPOS,$01
lda #RAMSTART_LO ; Initialize test address
sta $00
lda #RAMSTART_HI
sta $01
lda #$00
sta $10 ; Initialize page counters
sta $11 ; BCD version
ramCheckLoop:
ldy #$00 ; Store and retrieve the test value
lda #TESTVALUE
sta ($00),y
lda #$00
lda ($00),y
cmp #TESTVALUE
beq ramCheckNextAddr
jmp ramCheckFail
ramCheckNextAddr:
inc $00 ; Increment the 16-bit test address
bne ramCheckThresholds
inc $01
ramCheckThresholds:
lda $01
cmp #RAMEND_HI ; Have we reached the last address?
bne ramCheckPage
lda $00
cmp #RAMEND_LO
beq ramCheckSuccess
ramCheckPage:
ldy $01 ; Have we advanced another K?
dey
dey
tya
lsr a
lsr a
cmp $10
beq ramCheckLoop
sta $10
sed ; Increment BCD version of page counter
clc
lda $11
adc #$01
sta $11
cld
ldy #PLOTSTR ; Update display
sty GPUREG
pha
lsr a
lsr a
lsr a
lsr a
ora #'0'
sta GPUREG
ldy #PLOTSTR
sty GPUREG
pla
and #$0f
ora #'0'
sta GPUREG
lda #PLOTSTR
sta GPUREG
lda #'K'
sta GPUREG
GPUCMD CURSORXPOS,$00
GPUCMD CURSORYPOS,$01
jmp ramCheckLoop
ramCheckSuccess:
GPUCMD CURSORXPOS,$00 ; Print success message
GPUCMD CURSORYPOS,$02
GPUCMD FONTFGCLR,$0c
CALL16 printStr,success
jmp spinlock
ramCheckFail: ; Print failure message
GPUCMD CURSORXPOS,$00
GPUCMD CURSORYPOS,$02
GPUCMD FONTFGCLR,$00
GPUCMD FONTBGCLR,$30
CALL16 printStr,failure
jmp spinlock
;;;;;;;;;;;;;;;;;;;;;;;
; printStr
; Renders a null-terminated string at the current cursor location
; Args: $0000: Address of string
;
printStr:
ldy #$00
printStrLoop:
lda ($00),y ; Render the next character
beq printStrNull
tax
lda #PLOTSTR
sta GPUREG
txa
sta GPUREG
inc $00 ; Increment pointer
bne printStrLoop
inc $01
jmp printStrLoop
printStrNull:
rts
;;;;;;;;;;;;;;;;;;;;;;;
; delay
; Sleeps for ~1 second
; Args: None
;
delay:
pha ; Save registers
tya
pha
txa
pha
ldy #$ce ; Loop a bunch
delayOuter:
ldx #$ff
delayInner:
nop
nop
nop
nop
nop
nop
nop
dex
bne delayInner
dey
bne delayOuter
pla ; Restore registers
tax
pla
tay
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;
; spinLock
; Stalls CPU indefinitely
; Args: N/A
;
spinlock:
jmp spinlock
;;;;;;;;;;;;;;;;;;;;;;;
; Static strings
;
prompt:
.byte "VERONICA RAM CHECK",$00
success:
.byte "SUCCESS",$00
failure:
.byte "FAILED",$00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment