refactoring: macro for memset, memcpy, mov_word_mem

This commit is contained in:
giomba 2021-11-07 22:52:31 +01:00
parent 6e0d335b83
commit a8319e9fb7
3 changed files with 105 additions and 80 deletions

View File

@ -1,7 +1,5 @@
SEG zeropageSegment SEG zeropageSegment
; Generic src/dst copy pointers introDestPtr WORD
srcPointer DS 2
dstPointer DS 2
SEG programSegment SEG programSegment
introreset SUBROUTINE introreset SUBROUTINE
@ -19,9 +17,9 @@ introreset SUBROUTINE
; for "GLGPROGRAMS" at the beginning ; for "GLGPROGRAMS" at the beginning
ldx #$78 ldx #$78
stx dstPointer stx introDestPtr
ldy #$04 ldy #$04
sty dstPointer + 1 sty introDestPtr + 1
; GLGPROGRAMS color ; GLGPROGRAMS color
ldy #$00 ldy #$00
@ -57,29 +55,19 @@ statusIntro0 SUBROUTINE
and #$f8 and #$f8
sta $d011 sta $d011
ldy #0 ; ... clear text line ... MOV_WORD_MEM dstPointer, introDestPtr
lda #$80 MEMSET "D", #$80, #40
.clearLineLoop:
sta (dstPointer),y
iny
cpy #40
bne .clearLineLoop
clc ; ... move dstPointer to next text line ... clc ; ... move introDestPtr to next text line ...
lda dstPointer lda introDestPtr
adc #40 adc #40
sta dstPointer sta introDestPtr
lda dstPointer + 1 lda introDestPtr + 1
adc #0 adc #0
sta dstPointer + 1 sta introDestPtr + 1
ldy #$00 ; ... and copy "GLG Programs" text to next text line MOV_WORD_MEM dstPointer, introDestPtr
.glgLoop: MEMCPY "D", #GLGProgramsText, #200 ; ... and copy "GLG Programs" text to next text line
lda GLGProgramsText,y
sta (dstPointer),y
iny
cpy #200
bne .glgLoop
dec introYscroll ; remember that we are one line below dec introYscroll ; remember that we are one line below
beq .next ; if we reached the end of the vertical scroll, advance status beq .next ; if we reached the end of the vertical scroll, advance status
@ -196,7 +184,7 @@ GLGProgramsText: ; fancy PETSCII-looking brand name
statusIntro1 SUBROUTINE statusIntro1 SUBROUTINE
; continue moving moustaches down, up to 4 raster lines (middle of text) ; continue moving moustaches down, up to 4 raster lines (middle of text)
lda $d011 lda $d011
and #$07 and #$07
cmp #$04 cmp #$04
beq .next ; if interrupt is in the middle, don't move it anymore, and... beq .next ; if interrupt is in the middle, don't move it anymore, and...
@ -304,13 +292,7 @@ statusIntro4 SUBROUTINE
cmp #$02 cmp #$02
bne .end bne .end
lda #$80 MEMSET #$540, #$80, #200
ldy #$0
.loop:
sta $540,y
iny
cpy #200
bne .loop
lda #ST_INTRO5 lda #ST_INTRO5
sta status sta status
@ -426,36 +408,8 @@ statusMenuReset SUBROUTINE
bne .lastlineColorLoop bne .lastlineColorLoop
; Print Game Title: big "SNAKE" ; Print Game Title: big "SNAKE"
; color first MEMSET #$d800, #$02, #280 ; color
MEMSET #$d800, #$02, #150 MEMCPY #$400, #SnakeText, #280 ; text
; actual "text"
lda #$00
sta dstPointer
lda #$04
sta dstPointer + 1
ldx #<SnakeText
ldy #>SnakeText
stx srcPointer
sty srcPointer + 1
ldy #$00
.SnakeTitleLoop:
lda (srcPointer),y
sta (dstPointer),y
inc srcPointer
bne .noinc1
inc srcPointer + 1
.noinc1:
inc dstPointer
bne .noinc2
inc dstPointer + 1
.noinc2:
lda dstPointer
cmp #$18
bne .SnakeTitleLoop
lda dstPointer + 1
cmp #$05
bne .SnakeTitleLoop
; Print website ; Print website
lda #<intro2string ; lsb of string address lda #<intro2string ; lsb of string address

View File

@ -1,30 +1,101 @@
SEG zeropageSegment SEG zeropageSegment
ptrDstStart WORD ; Generic src/dst copy pointers
ptrDstEnd WORD srcPointer WORD
dstPointer WORD
dstPointerEnd WORD
SEG programSegment SEG programSegment
MACRO MEMSET MACRO MEMSET
IF {1} != "D"
clc clc
lda <{1} lda <{1}
sta ptrDstStart sta dstPointer
adc <({3} + 1) adc <{3}
sta ptrDstEnd sta dstPointerEnd
lda >{1} lda >{1}
sta ptrDstStart + 1 sta dstPointer + 1
adc >({3} + 1) adc >{3}
sta ptrDstEnd + 1 sta dstPointerEnd + 1
ELSE
clc
lda dstPointer
adc <{3}
sta dstPointerEnd
lda dstPointer + 1
adc >{3}
sta dstPointerEnd + 1
ENDIF
lda {2} lda {2}
ldy #0 ldy #0
.loop: .loop:
sta (ptrDstStart),y sta (dstPointer),y
inc ptrDstStart inc dstPointer
bne .skipInc bne .skipInc
inc ptrDstStart + 1 inc dstPointer + 1
.skipInc: .skipInc:
ldx ptrDstStart ldx dstPointer
cpx ptrDstEnd cpx dstPointerEnd
bne .loop bne .loop
ldx ptrDstStart + 1 ldx dstPointer + 1
cpx ptrDstEnd + 1 cpx dstPointerEnd + 1
bne .loop bne .loop
ENDM ENDM
SEG zeroPageSegment
SEG programSegment
MACRO MEMCPY
IF {1} != "D"
clc
lda <{1}
sta dstPointer
adc <{3}
sta dstPointerEnd
lda >{1}
sta dstPointer + 1
adc >{3}
sta dstPointerEnd + 1
ELSE
clc
lda dstPointer
adc <{3}
sta dstPointerEnd
lda dstPointer + 1
adc >{3}
sta dstPointerEnd + 1
ENDIF
lda <{2}
sta srcPointer
lda >{2}
sta srcPointer + 1
ldy #$0
.loop:
lda (srcPointer),y
sta (dstPointer),y
inc dstPointer
bne .skipIncDst
inc dstPointer + 1
.skipIncDst:
inc srcPointer
bne .skipIncSrc
inc srcPointer + 1
.skipIncSrc:
ldx dstPointer
cpx dstPointerEnd
bne .loop
ldx dstPointer + 1
cpx dstPointerEnd + 1
bne .loop
ENDM
SEG programSegment
MACRO MOV_WORD_MEM
lda {2}
sta {1}
lda {2} + 1
sta {1} + 1
ENDM

View File

@ -58,12 +58,12 @@ zeroFillZeroPage:
lda #ST_INTRO0 lda #ST_INTRO0
sta status sta status
; Enable interrupts
cli
; Reset screen (and other parameters) to play intro ; Reset screen (and other parameters) to play intro
jsr introreset jsr introreset
; Enable interrupts
cli
menu SUBROUTINE menu SUBROUTINE
.menu: ; Cycle here until SPACE or `Q` is pressed .menu: ; Cycle here until SPACE or `Q` is pressed
jsr $ffe4 ; GETIN jsr $ffe4 ; GETIN