Skip to content

Instantly share code, notes, and snippets.

@JettMonstersGoBoom
Last active September 12, 2022 21:00
Show Gist options
  • Save JettMonstersGoBoom/4783ae837a998ea45c691e689141c1a3 to your computer and use it in GitHub Desktop.
Save JettMonstersGoBoom/4783ae837a998ea45c691e689141c1a3 to your computer and use it in GitHub Desktop.
PCEngine Kickassembler simple sample.
// java -jar c:\Devtools\KickAssembler\KickAss65CE02-5.24e.jar base_pce.asm
.cpu _huc6280
.function _arg0(arg) {
.if ((arg.getType()==-6) || (arg.getType()==1) || (arg.getType()==17))
.return CmdArgument(arg.getType(),<arg.getValue())
.return CmdArgument(arg.getType(),arg.getValue())
}
.function _16bit_nextArgument(arg) {
.if ((arg.getType()==-6) || (arg.getType()==1) || (arg.getType()==17))
.return CmdArgument(arg.getType(),>arg.getValue())
.return CmdArgument(arg.getType(),arg.getValue()+1)
}
.pseudocommand mov16 src : tar {
lda _arg0(src)
sta _arg0(tar)
lda _16bit_nextArgument(src)
sta _16bit_nextArgument(tar)
}
.pseudocommand add16 arg1 : arg2 : tar {
.if (tar.getType()==AT_NONE) .eval tar=arg2
clc
lda _arg0(arg1)
adc _arg0(arg2)
sta _arg0(tar)
lda _16bit_nextArgument(arg1)
adc _16bit_nextArgument(arg2)
sta _16bit_nextArgument(tar)
}
.segment CARTRIDGE_FILE [outBin="boot.pce"]
// output CODE segment $e000-$ffff
// this is essentially the BOOT bank .
.segmentout [segments ="CODE"]
// data and code can go here
.segmentout [segments ="DATA"]
// currently we just setup $4000-$dfff as data ( so we don't worry about additional banks outside of 64kb )
.segmentdef CODE [start=$e000,min=$e000, max=$ffff, fill]
.segmentdef DATA [start=$4000,min=$4000, max=$dfff, fill]
// primary ZP not saved in the binary
.segment ZP [start=$2000]
// PCE
framesync: .byte 0
vsr: .byte 0
vdp_source: .word 0
vdp_attr: .word 0
vdp_dest: .word 0
cmpa: .byte 0
ticker: .byte 0
// RAM definitions
// not stored
.segment RWDATA [start=$2200]
// ram copy of sprite info 64 words.
Sprite_X:
.fill 128,0
Sprite_Y:
.fill 128,0
Sprite_ID:
.fill 128,0
Sprite_FLAGS:
.fill 128,0
.segment CODE
////// PCE module
.const VDC_MAWR = 0 // memory address write register
.const VDC_MARR = 1 // memory address read register
.const VDC_VRR = 2 // vram data register read
.const VDC_VWR = 3 // write
.const VDC_CR = 5 // control
.const VDC_RCR = 6 // raster counter
.const VDC_BXR = 7 // xscroll
.const VDC_BYR = 8 // yscroll
.const VDC_MWR = 9 // BG width
.const VDC_HSR = 10// h sync
.const VDC_HDR = 11// h display
.const VDC_VSR = 12// Vertical Synchro Register
.const VDC_VDR = 13// Vertical Display Register
.const VDC_VCR = 14// Vertical Display End Position Register
.const VDC_DMA_CR = 15 // DMA control
.const VDC_DMA_SRC = 16
.const VDC_DMA_DST = 17
.const VDC_DMA_LEN = 18
.const VDC_SAT_SRC = 19
.const VCE_DOT_CLOCK_10MHZ = %00000010
.const VCE_DOT_CLOCK_7MHZ = %00000001
.const VCE_DOT_CLOCK_5MHZ = %00000000
.const VDC_status = $0100
.const VDC_data_l = $0102
.const VDC_data_h = $0103
.const VCE_ADDRESS_l =$0402
.const VCE_ADDRESS_h =$0403
.const VCE_DATA_l =$0404
.const VCE_DATA_h =$0405
.const VDP_SPR_COL_ENABLE = %0000000000000001
.const VDP_SPR_OVERFLOW = %0000000000000010
.const VDP_RCR_ENABLE = %0000000000000100
.const VDP_IRQ_ENABLE = %0000000000001000
.const VDP_SPR_ENABLE = %0000000001000000
.const VDP_BG_ENABLE = %0000000010000000
.const VDP_INC_1 = %0000000000000000
.const VDP_INC_32 = %0000100000000000
.const VDP_INC_64 = %0001000000000000
.const VDP_INC_128 = %0001100000000000
// map sizes
.const MAP_32x32 = %00000000
.const MAP_64x32 = %00010000
.const MAP_128x32 = %00100000
.const MAP_32x64 = %01000000
.const MAP_64x64 = %01010000
.const MAP_128x64 = %01100000
// sprite flags
.const SPR_PRIORITY = %0000000010000000
.const SPR_X32 = %0000000100000000
.const SPR_XFLIP = %0000100000000000
.const SPR_Y16 = %0000000000000000
.const SPR_Y32 = %0001000000000000
.const SPR_Y64 = %0011000000000000
.const SPR_YFLIP = %1000000000000000
.const IRQ_DISABLE = $1402
.const IRQ_STATUS = $1403
.pseudocommand _vdc_reg reg : src {
st0 reg
st1 _arg0(src)
st2 _16bit_nextArgument(src)
}
.macro _vdc_256_wide()
{
st0 #VDC_HSR
st1 #$02
st2 #$02
st0 #VDC_HDR
st1 #$1f
st2 #$04
lda #VCE_DOT_CLOCK_5MHZ
sta $400
}
.macro _vdc_320_wide()
{
st0 #VDC_HSR
st1 #$02
st2 #$04
st0 #VDC_HDR
st1 #$29
st2 #$04
lda #VCE_DOT_CLOCK_7MHZ
sta $400
}
.macro _vdc_vsync()
{
stz.z framesync
wait_sync:
lda.z framesync
beq wait_sync
}
// copy from our sprite RAM table to the Hardware
_vdc_update_sprites:
{
st0 #$00
st1 #$00
st2 #$7f
st0 #2
ldx #$00
ldy #$00
loopSpr:
// Y
lda Sprite_Y,x
sta VDC_data_l
lda Sprite_Y+1,x
sta VDC_data_h
// X
lda Sprite_X,x
sta VDC_data_l
lda Sprite_X+1,x
sta VDC_data_h
lda Sprite_ID,x
sta VDC_data_l
lda Sprite_ID+1,x
sta VDC_data_h
lda Sprite_FLAGS,x
sta VDC_data_l
lda Sprite_FLAGS+1,x
sta VDC_data_h
inx
inx
iny
cpy #64
bne loopSpr
st0 #$13
st1 #$00
st2 #$7f
rts
}
// copy 16 colors
// mov16 #PaletteInfo:vdp_source
// mov16 #MemorySlot:vdp_dest
// #$0000 is palette 0
// #$0010 is palette 1
// #$0020 is palette 2 etc..
// #$0100 is sprite palette 0
// #$0110 is sprite palette 1 etc ..
// ldx #ColorCount
// jsr _VCE_upload
_VCE_upload:
{
lda.z vdp_dest
sta $0402 //st1 - L address
lda.z vdp_dest+1
sta $0403 //st2 - H Address
next:
ldy #$00
shcopy:
lda (vdp_source),y
sta $404
iny
lda (vdp_source),y
sta $405
iny
cpy #$20
bne shcopy
add16 #$20:vdp_source
dex
bne next
rts
}
PCE_vblank:
{
pha
phx
phy
lda VDC_status
sta.z vsr
and #$2
beq vsynccheck
stz $106
stz $106
vsynccheck:
lda.z vsr
and #$20
beq exit
jsr _vdc_update_sprites
// jsr _VDC_upload_SATB
inc.z framesync
exit:
lda #$00
sta VDC_status
ply
plx
pla
irq2:
rti
}
PCE_hblank:
{
rti
}
PCE_timer:
{
sta $1403 //ACK TIMER
stz $0c01 //Turn off timer
rti
}
////// end of PCE module
Start:
{
sei
csh // Change Speed High
cld // Clear Decimal Flag
stz $0c00
ldx #$ff
txs
lda #$ff // hardware $0000-$1fff
tam #%00000001
lda #$f8 // ram $2000-$3fff
tam #%00000010
lda #1 // prgrom1 $4000-$5fff
tam #%00000100
lda #2 // prgrom2 $6000-$7fff
tam #%00001000
lda #3 // prgrom3 $8000-$afff
tam #%00010000
lda #4 // prgrom4 $c000-$dfff
tam #%00100000
lda #0 // prgrom0 $e000-$ffff
tam #%01000000
stz $2000 // clear all the RAM
tii $2000,$2001,$1FFF
lda #$7
sta $1402
stz $1403
_vdc_reg #VDC_CR:#0
_vdc_reg #VDC_RCR:#0
_vdc_reg #VDC_BXR:#0
_vdc_reg #VDC_BYR:#$0000
_vdc_reg #VDC_MWR:#MAP_64x32
_vdc_reg #VDC_VSR:#$0d07
_vdc_reg #VDC_VDR:#$00df
_vdc_reg #VDC_VCR:#$0003
_vdc_reg #VDC_DMA_CR:#%00010001
_vdc_reg #VDC_SAT_SRC:#$7f00
mov16 #SpriteData:vdp_source
mov16 #$4000:vdp_dest
ldx #$4
ldy #$00
jsr _VDC_upload
mov16 #SprColors:vdp_source
mov16 #$0100:vdp_dest
ldx #16
jsr _VCE_upload
_vdc_320_wide()
_vdc_reg #VDC_CR:#(VDP_IRQ_ENABLE | VDP_BG_ENABLE | VDP_SPR_ENABLE )
// PCE
lda #%00000001
sta IRQ_DISABLE
stz IRQ_STATUS
cli
// game loop
vwait:
_vdc_vsync()
inc.z ticker
ldx.z ticker
clc
lda Curve,x
adc #$40
sta Sprite_X
lda #$00
adc #00
sta Sprite_X+1
txa
clc
adc #$40
tax
clc
lda Curve,x
adc #$40
sta Sprite_Y
lda #$00
adc #00
sta Sprite_Y+1
mov16 #$4000/$20:Sprite_ID
mov16 #SPR_PRIORITY:Sprite_FLAGS
jmp vwait
}
_VDC_upload:
{
st0 #0 //Select Memory Write Reg
lda.z vdp_dest
sta $0102 //st1 - L address
lda.z vdp_dest+1
sta $0103 //st2 - H Address
st0 #2
sty.z cmpa
next:
ldy #$00
shcopy:
lda (vdp_source),y
sta $102
iny
lda (vdp_source),y
sta $103
iny
cpy.z cmpa
bne shcopy
inc.z vdp_source+1
cpx #0
beq exit
lda #00
sta.z cmpa
dex
jmp shcopy
exit:
rts
}
.align 256
Curve:
.fill 256, 100.5 + 100.5*sin(toRadians(i*360/256))
//#import "modules/joystick.asm"
* = $fff6
.word PCE_hblank
.word PCE_vblank
.word PCE_timer
.word 0
* = $fffe
.word Start
.segment DATA "Tiles"
SpriteData:
.byte $F0, $0F, $0C, $30, $02, $5E, $02, $5E, $01, $BE, $01, $BE
.byte $01, $BC, $01, $80, $01, $80, $01, $80, $01, $80, $01, $80
.byte $02, $40, $02, $40, $0C, $30, $F0, $0F, $00, $00, $00, $00
.byte $00, $1E, $00, $1E, $00, $3E, $00, $3E, $00, $3C, $00, $00
.byte $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
.byte $00, $00, $00, $00, $00, $00, $F0, $0F, $FC, $21, $FC, $21
.byte $FE, $41, $FE, $41, $FE, $43, $FE, $7F, $FE, $7F, $FE, $7F
.byte $FE, $7F, $FE, $7F, $FC, $3F, $FC, $3F, $F0, $0F, $00, $00
.byte $00, $00, $F0, $0F, $FC, $3F, $FC, $3F, $FE, $7F, $FE, $7F
.byte $FE, $7F, $FE, $7F, $FE, $7F, $FE, $7F, $FE, $7F, $FE, $7F
.byte $FC, $3F, $FC, $3F, $F0, $0F, $00, $00
SprColors:
.word $000,$222,$444,$666,$888,$aaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment