nuclear@0: ; vi:ft=rgbasm: nuclear@0: include "hw.inc" nuclear@0: nuclear@0: xoffs_center equ 4 nuclear@0: yoffs_center equ 12 nuclear@0: nuclear@0: frame_ptr equ $ff80 nuclear@0: nuclear@0: section "hdr", ROM0[$100] nuclear@0: nop nuclear@0: jp main nuclear@0: nuclear@0: rept $150 - $104 nuclear@0: db 0 nuclear@0: endr nuclear@0: nuclear@0: section "text", ROM0 nuclear@0: nuclear@0: main: nuclear@0: call init nuclear@0: nuclear@0: xor a, a nuclear@0: ldh [frame_ptr], a nuclear@0: .mainloop: nuclear@0: ldh a, [REG_LY] nuclear@0: cp a, 144 nuclear@0: jr c, .wait_hsync nuclear@0: nuclear@0: ; we're in vsync, increment frame counter and wait for the next frame nuclear@0: ldh a, [frame_ptr] nuclear@0: inc a nuclear@0: ldh [frame_ptr], a nuclear@0: .wait_newframe: nuclear@0: ldh a, [REG_LY] nuclear@0: cp a, 0 nuclear@0: jr nz, .wait_newframe nuclear@0: nuclear@0: ; scanline code nuclear@0: .wait_hsync: nuclear@0: ldh a, [REG_STAT] nuclear@0: and a, STAT_MODE_MASK nuclear@0: jr nz, .wait_hsync nuclear@0: nuclear@0: ldh a, [frame_ptr] nuclear@0: ld d, a nuclear@0: nuclear@0: xor a, a nuclear@0: ld b, a nuclear@1: nuclear@0: ldh a, [REG_LY] nuclear@1: add a, d ; add frame number nuclear@0: ld c, a nuclear@0: nuclear@0: ld hl, sintab nuclear@1: add hl, bc ; hl now points to the sine value nuclear@0: nuclear@1: ld a, [hl] nuclear@1: nuclear@1: ; add a half-octave sine nuclear@1: ld e, a ; save first sine to e nuclear@1: sla d nuclear@1: ld a, [REG_LY] nuclear@1: sla a nuclear@1: add a, d nuclear@1: ld c, a nuclear@1: srl d nuclear@1: nuclear@1: ld hl, sintab nuclear@1: add hl, bc nuclear@1: ld a, [hl] nuclear@1: sra a nuclear@1: add a, e ; add previously saved sine nuclear@1: nuclear@1: add a, yoffs_center nuclear@0: ldh [REG_SCY], a nuclear@0: nuclear@1: ; do something for SCX too nuclear@1: ld a, d nuclear@1: sla a nuclear@1: ld d, a nuclear@1: nuclear@1: ldh a, [REG_LY] nuclear@1: add a, 32 nuclear@1: add a, d ; add frame number nuclear@1: ld c, a nuclear@1: nuclear@1: ld hl, sintab nuclear@1: add hl, bc nuclear@1: nuclear@1: ld a, [hl] nuclear@1: sra a nuclear@1: add a, xoffs_center nuclear@1: ldh [REG_SCX], a nuclear@1: nuclear@0: ; done, wait until we're out of hsync nuclear@0: .wait_endhsync: nuclear@0: ldh a, [REG_STAT] nuclear@0: and a, STAT_MODE_MASK nuclear@0: jr z, .wait_endhsync nuclear@0: nuclear@0: jr .mainloop nuclear@0: nuclear@0: nuclear@0: di nuclear@0: .end: halt nuclear@0: nop nuclear@0: jp .end nuclear@0: nuclear@0: init: nuclear@0: call wait_vsync nuclear@0: xor a, a nuclear@0: ldh [REG_LCDC], a nuclear@0: nuclear@2: ; setup palette nuclear@0: ld a, $1b nuclear@0: ldh [REG_BGP], a nuclear@0: nuclear@0: ; copy tiles nuclear@0: ld hl, $8000 nuclear@0: ld de, tiles nuclear@0: ld bc, tiles_end - tiles nuclear@0: .copytiles: nuclear@0: ld a, [de] nuclear@0: ld [hl+], a nuclear@0: inc de nuclear@0: dec bc nuclear@0: ld a, b nuclear@0: or c nuclear@0: jp nz, .copytiles nuclear@0: nuclear@0: ; copy tilemap nuclear@0: ld hl, $9800 nuclear@0: ld de, tilemap nuclear@0: ld b, 21 nuclear@0: .copymap: nuclear@0: ld c, 21 nuclear@0: .copymaprow: nuclear@0: ld a, [de] nuclear@0: inc de nuclear@0: ld [hl+], a nuclear@0: dec c nuclear@0: jr nz, .copymaprow nuclear@0: nuclear@0: push bc nuclear@0: ld bc, 11 nuclear@0: add hl, bc nuclear@0: pop bc nuclear@0: nuclear@0: dec b nuclear@0: jr nz, .copymap nuclear@0: nuclear@0: ; center viewport nuclear@0: ld a, yoffs_center nuclear@0: ldh [REG_SCY], a nuclear@0: ld a, xoffs_center nuclear@0: ldh [REG_SCX], a nuclear@0: nuclear@0: ; configure LCD nuclear@0: ld a, LCDC_DISPON | LCDC_CHAR_8000 | LCDC_BGON nuclear@0: ldh [REG_LCDC], a nuclear@0: ret nuclear@0: nuclear@0: wait_vsync: nuclear@0: ldh a, [REG_LY] nuclear@0: cp a, 144 nuclear@0: jr c, wait_vsync nuclear@0: ret nuclear@0: nuclear@0: section "data", ROM0, align[8] nuclear@0: sintab: nuclear@0: include "sin.inc" nuclear@0: nuclear@0: tiles: nuclear@0: incbin "logo.tiles" nuclear@0: tiles_end: nuclear@0: tilemap: nuclear@0: incbin "logo.tilemap" nuclear@0: tilemap_end: