Last active
March 9, 2016 11:07
-
-
Save freem/b36f2bcb37287cf713d4 to your computer and use it in GitHub Desktop.
possible solution for getting around the zero page problem with pceas and ca65
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; macro: pcezp | |
;; Writes a PCE-relative zero page address (e.g. $2000-$3FFF) | |
;; __PCE_ZP_START__ must be defined in your linker configuration. | |
;; | |
.macro pcezp opcode,value | |
opcode __PCE_ZP_START__+value | |
.endmacro | |
;; | |
;; macro: realzp | |
;; Writes a real-relative zero page address (e.g. $00-$FF) | |
;; | |
.macro realzp opcode,value | |
opcode value | |
.endmacro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# linker script for pce assembly projects using ld65 | |
MEMORY { | |
ZP: start = $0000, size = $100, type = rw, define = yes; | |
# Assumes hardware page $F8 is in MPR1 ($2000-$3FFF) | |
RAM: start = $2200, size $1E00, define = yes; | |
# reset bank and hardware vectors (MPR7) | |
ROM00: start = $E000, size = $1FF6, file = %O, fill = yes, bank = $00, define = yes; | |
VECTORS: start = $FFF6, size = $000A, file = %O, fill = yes; | |
# other banks | |
} | |
SEGMENTS { | |
ZEROPAGE: load = ZP, type = zp, define = yes; | |
BSS: load = RAM, type = bss, define = yes; | |
CODE: load = ROM00, type = ro, define = yes; | |
RODATA: load = ROM00, type = ro, define = yes; | |
DATA: load = ROM00, run = RAM, type = rw, define = yes; | |
VECTORS: load = VECTORS, type = ro, define = yes; | |
} | |
SYMBOLS { | |
__PCE_ZP_START__: type = export, value = $2000; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; macro: pcezp | |
;; Writes a PCE-relative zero page address (e.g. $2000-$3FFF) | |
;; | |
.macro pcezp | |
\1 \2 | |
.endmacro | |
;; | |
;; macro: realzp | |
;; Writes a real-relative zero page address (e.g. $00-$FF) | |
;; | |
.macro realzp | |
\1 <\2 | |
.endmacro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.include "pce.inc" | |
.macro pcezp opcode,value | |
opcode __PCE_ZP_START__+value | |
.endmacro | |
.macro realzp opcode,value | |
opcode value | |
.endmacro | |
.bss | |
regram: .res 2 | |
.zeropage | |
regzp: .res 2 | |
.segment "VECTORS" | |
.addr fakeIRQ ; IRQ2 | |
.addr fakeIRQ ; IRQ1 | |
.addr timerIRQ ; Timer | |
.addr fakeIRQ ; NMI | |
.addr Reset | |
.code | |
.import __PCE_ZP_START__ ; imported from linker, should be set to $2000 | |
Reset: | |
sei | |
csh | |
cld | |
ldx #$FF | |
txs | |
txa | |
tam0 | |
lda #$F8 | |
tam1 | |
; clear all ram | |
stz __PCE_ZP_START__ | |
tii __PCE_ZP_START__,__PCE_ZP_START__+1,$1FFF | |
ldx #$65 | |
ldy #$02 | |
;-- write to BSS/$2200 --; | |
stx regram | |
sty regram+1 | |
;-- write to real zero page/$0000 --; | |
; without macro: | |
;stx regzp | |
;sty regzp+1 | |
; with macro: | |
realzp stx,regzp | |
realzp sty,regzp+1 | |
;-- write to pce zero page/$2000 --; | |
; without macro: | |
;stx __PCE_ZP_START__+regzp | |
;sty __PCE_ZP_START__+regzp+1 | |
; with macro: | |
pcezp stx,regzp | |
pcezp sty,regzp+1 | |
; absolute,y addressing | |
ldy #0 | |
lda regzp+__PCE_ZP_START__,y | |
; (zp),y addressing | |
lda (regzp),y | |
forever: | |
bra forever | |
fakeIRQ: | |
rti | |
timerIRQ: | |
stz IRQ_STATUS | |
rti |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.bss | |
regram: ds 2 | |
.zp | |
regzp: ds 2 | |
.macro pcezp | |
\1 \2 | |
.endmacro | |
.macro realzp | |
\1 <\2 | |
.endmacro | |
.data | |
.bank 0 | |
.org $FFF6 | |
.dw fakeIRQ ; IRQ2 | |
.dw fakeIRQ ; IRQ1 | |
.dw timerIRQ ; Timer | |
.dw fakeIRQ ; NMI | |
.dw Reset | |
.code | |
.bank 0 | |
.org $E000 | |
Reset: | |
sei | |
csh | |
cld | |
ldx #$FF | |
txs | |
txa | |
tam0 | |
lda #$F8 | |
tam1 | |
; clear all ram | |
stz $2000 | |
tii $2000,$2001,$1FFF | |
ldx #$65 | |
ldy #$02 | |
;-- write to BSS/$2200 --; | |
stx regram | |
sty regram+1 | |
;-- write to real zero page/$0000 --; | |
; without macro: | |
;stx <regzp | |
;sty <regzp+1 | |
; with macro: | |
realzp stx,regzp | |
realzp sty,regzp+1 | |
;-- write to pce zero page/$2000 --; | |
; without macro: | |
;stx regzp | |
;sty regzp+1 | |
pcezp stx,regzp | |
pcezp sty,regzp+1 | |
; absolute,y addressing | |
ldy #0 | |
lda regzp,y | |
; [zp],y addressing | |
lda [regzp],y | |
forever: | |
bra forever | |
fakeIRQ: | |
rti | |
timerIRQ: | |
stz $1403 | |
rti |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment