diff options
author | Juan J. Martinez <jjm@usebox.net> | 2020-12-30 19:07:31 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2020-12-30 19:23:41 +0000 |
commit | 2682bc5d1d864341aaeb42a449db73c3ecd16d70 (patch) | |
tree | 9116764364b4ee0ce7f6037305077807b57776de /src/ubox | |
download | ubox-msx-lib-1.0.tar.gz ubox-msx-lib-1.0.zip |
Initial import1.0
Diffstat (limited to 'src/ubox')
27 files changed, 731 insertions, 0 deletions
diff --git a/src/ubox/Makefile b/src/ubox/Makefile new file mode 100644 index 0000000..a597090 --- /dev/null +++ b/src/ubox/Makefile @@ -0,0 +1,19 @@ +LIB=../../lib/ubox.lib +all: $(LIB) + +AS=sdasz80 +AR=sdar + +SOURCES=$(wildcard ubox_*.z80) +OBJS=$(patsubst %.z80,%.rel,$(SOURCES)) + +$(LIB): $(OBJS) + $(AR) -rcD $(LIB) $(OBJS) + +%.rel: %.z80 + $(AS) -o $< + +.PHONY: clean +clean: + rm -f $(OBJS) $(LIB) + diff --git a/src/ubox/ubox_disable_screen.z80 b/src/ubox/ubox_disable_screen.z80 new file mode 100644 index 0000000..767f335 --- /dev/null +++ b/src/ubox/ubox_disable_screen.z80 @@ -0,0 +1,7 @@ +.globl _ubox_disable_screen + +DISSCR = 0x0041 + +_ubox_disable_screen:: + jp DISSCR + diff --git a/src/ubox/ubox_enable_screen.z80 b/src/ubox/ubox_enable_screen.z80 new file mode 100644 index 0000000..8ab0361 --- /dev/null +++ b/src/ubox/ubox_enable_screen.z80 @@ -0,0 +1,7 @@ +.globl _ubox_enable_screen + +ENASCR = 0x0044 + +_ubox_enable_screen:: + jp ENASCR + diff --git a/src/ubox/ubox_fill_screen.z80 b/src/ubox/ubox_fill_screen.z80 new file mode 100644 index 0000000..ed8c58f --- /dev/null +++ b/src/ubox/ubox_fill_screen.z80 @@ -0,0 +1,10 @@ +.globl _ubox_fill_screen + +FILVRM = 0x0056 + +_ubox_fill_screen:: + ld a, l + ld hl, #0x1800 + ld bc, #768 + jp FILVRM + diff --git a/src/ubox/ubox_get_tile.z80 b/src/ubox/ubox_get_tile.z80 new file mode 100644 index 0000000..49dcb30 --- /dev/null +++ b/src/ubox/ubox_get_tile.z80 @@ -0,0 +1,28 @@ +.globl _ubox_get_tile + +RDVRM = 0x004a + +_ubox_get_tile:: + ld hl, #2 + add hl, sp + + ld b, #0 + ld c, (hl) + inc hl + ld l, (hl) + + ld h, #0 + add hl, hl + add hl, hl + add hl, hl + add hl, hl + add hl, hl + add hl, bc + + ld bc, #0x1800 + add hl, bc + + call RDVRM + ld l, a + ret + diff --git a/src/ubox/ubox_get_vsync_freq.z80 b/src/ubox/ubox_get_vsync_freq.z80 new file mode 100644 index 0000000..681fe67 --- /dev/null +++ b/src/ubox/ubox_get_vsync_freq.z80 @@ -0,0 +1,9 @@ +.globl _ubox_get_vsync_freq + +_ubox_get_vsync_freq:: + ld a, (#0x002b) + and #128 + ld l, a + ret z + ld l, #1 + ret diff --git a/src/ubox/ubox_isr.z80 b/src/ubox/ubox_isr.z80 new file mode 100644 index 0000000..cceb2c6 --- /dev/null +++ b/src/ubox/ubox_isr.z80 @@ -0,0 +1,79 @@ +.globl _ubox_init_isr +.globl _ubox_tick +.globl ubox_isr_wait_ticks +.globl ubox_isr_wait_tick +.globl ubox_usr_isr +.globl ___sdcc_call_hl + +HTIMI_HOOK = 0xfd9f + +SCNCNT = 0xf3f6 +REPCNT = 0xf3f7 + +_ubox_init_isr:: + di + ld a, l + ld (ubox_isr_wait_ticks), a + xor a + ld (ubox_isr_wait_tick), a + ld (_ubox_tick), a + ld (ubox_usr_isr), a + ld (ubox_usr_isr+1), a + ld hl, #ubox_isr + ex de, hl + ld hl, #HTIMI_HOOK + ld a, #0xc3 + ld (hl), a + inc hl + ld (hl), e + inc hl + ld (hl), d + ei + ret + +ubox_isr: + push af + push ix + push iy + push bc + push hl + push de + + ; stop BIOS reading keyboard buffer + xor a + ld (SCNCNT), a + ld (REPCNT), a + + ld hl, #ubox_isr_wait_tick + inc (hl) + inc hl + inc (hl) + inc hl + inc hl + + ; check user isr, only MSB + ld a, (hl) + or a + jr z, no_user_isr + + dec hl + ld l, (hl) + ld h, a + call ___sdcc_call_hl + +no_user_isr: + pop de + pop hl + pop bc + pop iy + pop ix + pop af + ret + +.area _DATA + +ubox_isr_wait_ticks: .ds 1 +ubox_isr_wait_tick: .ds 1 +_ubox_tick: .ds 1 + +ubox_usr_isr: .ds 2 diff --git a/src/ubox/ubox_put_tile.z80 b/src/ubox/ubox_put_tile.z80 new file mode 100644 index 0000000..1bdf3ce --- /dev/null +++ b/src/ubox/ubox_put_tile.z80 @@ -0,0 +1,30 @@ +.globl _ubox_put_tile + +WRTVRM = 0x004d + +_ubox_put_tile:: + ld hl, #2 + add hl, sp + + ld c, (hl) + inc hl + ld b, (hl) + inc hl + + ld a, (hl) + + ld h, #0 + ld l, b + add hl, hl + add hl, hl + add hl, hl + add hl, hl + add hl, hl + ld b, #0 + add hl, bc + + ld bc, #0x1800 + add hl, bc + + jp WRTVRM + diff --git a/src/ubox/ubox_read_ctl.z80 b/src/ubox/ubox_read_ctl.z80 new file mode 100644 index 0000000..91963c0 --- /dev/null +++ b/src/ubox/ubox_read_ctl.z80 @@ -0,0 +1,100 @@ +.globl _ubox_read_ctl + +RDPSG = 0x0096 +WRTPSG = 0x0093 +SNSMAT = 0x0141 + +_ubox_read_ctl:: + ld a, l + or a + jr z, is_keyb + dec a + jr z, is_joy1 + dec a + jr z, is_joy2 + + ld l, #0 + ret + +is_joy2: + ; select + ld e, #0xcf + jr call_psg + +is_joy1: + ; select + ld e, #0x8f + +call_psg: + ld a, #0x0f + call WRTPSG + + ld a, #0x0e + + di + call RDPSG + ei + cpl + and #0x3f + ld e, a + + ; button 2 (M) + ld a, #4 + call SNSMAT + rra + rra + rra + ld a, #0x20 + jr nc, joy_extra_m + xor a +joy_extra_m: + or e + ld l, a + ret + +is_keyb: + ; button 2 (M) + ld a, #4 + call SNSMAT + rra + rra + rra + ld e, #0x20 + jr nc, is_keyb_dir + + ld e, #0 + +is_keyb_dir: + ; direction + ld a, #8 + call SNSMAT + cpl + rrca + rrca + ld c, a + + and #4 + ld b, a + ; b has left + + ld a, c + rrca + rrca + ld c, a + + and #0x18 + or b + ld b, a + ; added space and right + + ld a, c + rrca + and #3 + or b + ; added down and up + + or e + ; added 2nd fire (M) + + ld l, a + ret diff --git a/src/ubox/ubox_read_keys.z80 b/src/ubox/ubox_read_keys.z80 new file mode 100644 index 0000000..d32f2de --- /dev/null +++ b/src/ubox/ubox_read_keys.z80 @@ -0,0 +1,10 @@ +.globl _ubox_read_keys + +SNSMAT = 0x0141 + +_ubox_read_keys:: + ld a, l + call SNSMAT + cpl + ld l, a + ret diff --git a/src/ubox/ubox_read_vm.z80 b/src/ubox/ubox_read_vm.z80 new file mode 100644 index 0000000..7ef0f41 --- /dev/null +++ b/src/ubox/ubox_read_vm.z80 @@ -0,0 +1,23 @@ +.globl _ubox_read_vm + +LDIRMV = 0x0059 + +_ubox_read_vm:: + ld hl, #2 + add hl, sp + + ld e, (hl) + inc hl + ld d, (hl) + inc hl + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld a, (hl) + inc hl + ld h, (hl) + ld l, a + + jp LDIRMV + diff --git a/src/ubox/ubox_reset_tick.z80 b/src/ubox/ubox_reset_tick.z80 new file mode 100644 index 0000000..96bb1bf --- /dev/null +++ b/src/ubox/ubox_reset_tick.z80 @@ -0,0 +1,10 @@ +.globl _ubox_reset_tick +.globl _ubox_tick + +_ubox_reset_tick:: + xor a + di + ld (_ubox_tick), a + ei + ret + diff --git a/src/ubox/ubox_select_ctl.z80 b/src/ubox/ubox_select_ctl.z80 new file mode 100644 index 0000000..9685bec --- /dev/null +++ b/src/ubox/ubox_select_ctl.z80 @@ -0,0 +1,42 @@ +.globl _ubox_select_ctl + +GTTRIG = 0x00d8 + +_ubox_select_ctl:: + ld b, #3 +loop: + ld a, b + dec a + push bc + call GTTRIG + pop bc + or a + jr nz, trigger + djnz loop + + ; 2nd button + + ld b, #4 + ld a, b + push bc + call GTTRIG + pop bc + or a + jr nz, trigger_b + + dec b + ld a, b + push bc + call GTTRIG + pop bc + or a + jr nz, trigger_b + + ld l, #0xff + ret +trigger_b: + dec b +trigger: + dec b + ld l, b + ret diff --git a/src/ubox/ubox_set_colors.z80 b/src/ubox/ubox_set_colors.z80 new file mode 100644 index 0000000..b4638b8 --- /dev/null +++ b/src/ubox/ubox_set_colors.z80 @@ -0,0 +1,23 @@ +.globl _ubox_set_colors + +CHGCLR = 0x0062 +FORCLR = 0xf3e9 +BAKCLR = 0xf3ea +BDRCLR = 0xf3eb + +_ubox_set_colors:: + ld hl, #2 + add hl, sp + + ld a, (hl) + inc hl + ld (FORCLR), a + ld a, (hl) + inc hl + ld (BAKCLR), a + ld a, (hl) + inc hl + ld (BDRCLR), a + call CHGCLR + ret + diff --git a/src/ubox/ubox_set_mode.z80 b/src/ubox/ubox_set_mode.z80 new file mode 100644 index 0000000..4635d34 --- /dev/null +++ b/src/ubox/ubox_set_mode.z80 @@ -0,0 +1,8 @@ +.globl _ubox_set_mode + +CHGMOD = 0x005f + +_ubox_set_mode:: + ld a, l + jp CHGMOD + diff --git a/src/ubox/ubox_set_sprite_attr.z80 b/src/ubox/ubox_set_sprite_attr.z80 new file mode 100644 index 0000000..fe573b6 --- /dev/null +++ b/src/ubox/ubox_set_sprite_attr.z80 @@ -0,0 +1,29 @@ +.globl _ubox_set_sprite_attr +.globl _ubox_write_vm + +_ubox_set_sprite_attr:: + ld hl, #2 + add hl, sp + + ld e, (hl) + inc hl + ld d, (hl) + inc hl + + ld l, (hl) + sla l + sla l + ld h, #0 + ld bc, #0x1b00 + add hl, bc + + push de + ld bc, #4 + push bc + push hl + call _ubox_write_vm + pop af + pop af + pop af + ret + diff --git a/src/ubox/ubox_set_sprite_pat16.z80 b/src/ubox/ubox_set_sprite_pat16.z80 new file mode 100644 index 0000000..4689267 --- /dev/null +++ b/src/ubox/ubox_set_sprite_pat16.z80 @@ -0,0 +1,32 @@ +.globl _ubox_set_sprite_pat16 +.globl _ubox_write_vm + +_ubox_set_sprite_pat16:: + ld hl, #2 + add hl, sp + + ld e, (hl) + inc hl + ld d, (hl) + inc hl + + ld l, (hl) + ld h, #0 + add hl, hl + add hl, hl + add hl, hl + add hl, hl + add hl, hl + ld bc, #0x3800 + add hl, bc + + push de + ld bc, #32 + push bc + push hl + call _ubox_write_vm + pop af + pop af + pop af + ret + diff --git a/src/ubox/ubox_set_sprite_pat16_flip.z80 b/src/ubox/ubox_set_sprite_pat16_flip.z80 new file mode 100644 index 0000000..bb960f8 --- /dev/null +++ b/src/ubox/ubox_set_sprite_pat16_flip.z80 @@ -0,0 +1,63 @@ +.globl _ubox_set_sprite_pat16_flip + +WRTVRM = 0x004d + +_ubox_set_sprite_pat16_flip:: + ld hl, #2 + add hl, sp + + ld e, (hl) + inc hl + ld d, (hl) + inc hl + + ld l, (hl) + ld h, #0 + add hl, hl + add hl, hl + add hl, hl + add hl, hl + add hl, hl + ld bc, #0x3800 + add hl, bc + + push de + ld bc, #16 + ex de, hl + add hl, bc + ex de, hl + call flip + + pop de + call flip + + ret + +flip: + ld b, #16 +flip0: + call flip_and_copy + inc hl + inc de + djnz flip0 + ret + +flip_and_copy: + ld a, (de) + ld c, a + rlca + rlca + xor c + and #0xaa + xor c + ld c, a + rlca + rlca + rlca + rrc c + xor c + and #0x66 + xor c + + jp WRTVRM + diff --git a/src/ubox/ubox_set_sprite_pat8.z80 b/src/ubox/ubox_set_sprite_pat8.z80 new file mode 100644 index 0000000..11b0205 --- /dev/null +++ b/src/ubox/ubox_set_sprite_pat8.z80 @@ -0,0 +1,30 @@ +.globl _ubox_set_sprite_pat8 +.globl _ubox_write_vm + +_ubox_set_sprite_pat8:: + ld hl, #2 + add hl, sp + + ld e, (hl) + inc hl + ld d, (hl) + inc hl + + ld l, (hl) + ld h, #0 + add hl, hl + add hl, hl + add hl, hl + ld bc, #0x3800 + add hl, bc + + push de + ld bc, #8 + push bc + push hl + call _ubox_write_vm + pop af + pop af + pop af + ret + diff --git a/src/ubox/ubox_set_sprite_pat8_flip.z80 b/src/ubox/ubox_set_sprite_pat8_flip.z80 new file mode 100644 index 0000000..a3f8d1d --- /dev/null +++ b/src/ubox/ubox_set_sprite_pat8_flip.z80 @@ -0,0 +1,48 @@ +.globl _ubox_set_sprite_pat8_flip + +WRTVRM = 0x004d + +_ubox_set_sprite_pat8_flip:: + ld hl, #2 + add hl, sp + + ld e, (hl) + inc hl + ld d, (hl) + inc hl + + ld l, (hl) + ld h, #0 + add hl, hl + add hl, hl + add hl, hl + ld bc, #0x3800 + add hl, bc + + ld b, #8 +flip0: + call flip_and_copy + inc hl + inc de + djnz flip0 + ret + +flip_and_copy: + ld a, (de) + ld c, a + rlca + rlca + xor c + and #0xaa + xor c + ld c, a + rlca + rlca + rlca + rrc c + xor c + and #0x66 + xor c + + jp WRTVRM + diff --git a/src/ubox/ubox_set_tiles.z80 b/src/ubox/ubox_set_tiles.z80 new file mode 100644 index 0000000..fbb2ff9 --- /dev/null +++ b/src/ubox/ubox_set_tiles.z80 @@ -0,0 +1,21 @@ +.globl _ubox_set_tiles + +LDIRVM = 0x005c + +_ubox_set_tiles:: + ld de, #0 + ld bc, #256 * 8 + push hl + call LDIRVM + pop hl + + ld de, #256 * 8 + ld bc, #256 * 8 + push hl + call LDIRVM + pop hl + + ld de, #256 * 8 * 2 + ld bc, #256 * 8 + jp LDIRVM + diff --git a/src/ubox/ubox_set_tiles_colors.z80 b/src/ubox/ubox_set_tiles_colors.z80 new file mode 100644 index 0000000..8ba2609 --- /dev/null +++ b/src/ubox/ubox_set_tiles_colors.z80 @@ -0,0 +1,21 @@ +.globl _ubox_set_tiles_colors + +LDIRVM = 0x005c + +_ubox_set_tiles_colors:: + ld de, #0x2000 + ld bc, #256 * 8 + push hl + call LDIRVM + pop hl + + ld de, #0x2000 + 256 * 8 + ld bc, #256 * 8 + push hl + call LDIRVM + pop hl + + ld de, #0x2000 + 256 * 8 * 2 + ld bc, #256 * 8 + jp LDIRVM + diff --git a/src/ubox/ubox_set_user_isr.z80 b/src/ubox/ubox_set_user_isr.z80 new file mode 100644 index 0000000..5722909 --- /dev/null +++ b/src/ubox/ubox_set_user_isr.z80 @@ -0,0 +1,8 @@ +.globl _ubox_set_user_isr +.globl ubox_usr_isr + +_ubox_set_user_isr:: + di + ld (ubox_usr_isr), hl + ei + ret diff --git a/src/ubox/ubox_wait.z80 b/src/ubox/ubox_wait.z80 new file mode 100644 index 0000000..49fd0be --- /dev/null +++ b/src/ubox/ubox_wait.z80 @@ -0,0 +1,23 @@ +.globl _ubox_wait +.globl ubox_isr_wait_ticks +.globl ubox_isr_wait_tick + +_ubox_wait:: + ld hl, #ubox_isr_wait_tick + ld a, (ubox_isr_wait_ticks) + ld c, a + +wait_loop: + ld a, (hl) + cp c + jr nc, wait_done + halt + jr wait_loop + +wait_done: + xor a + di + ld (hl), a + ei + ret + diff --git a/src/ubox/ubox_wait_for.z80 b/src/ubox/ubox_wait_for.z80 new file mode 100644 index 0000000..5cc4649 --- /dev/null +++ b/src/ubox/ubox_wait_for.z80 @@ -0,0 +1,14 @@ +.globl _ubox_wait_for +.globl _ubox_wait +.globl ubox_isr_wait_ticks +.globl ubox_isr_wait_tick + +_ubox_wait_for:: + ld b, l +wait_for_loop: + push bc + call _ubox_wait + pop bc + djnz wait_for_loop + ret + diff --git a/src/ubox/ubox_write_vm.z80 b/src/ubox/ubox_write_vm.z80 new file mode 100644 index 0000000..3d6606b --- /dev/null +++ b/src/ubox/ubox_write_vm.z80 @@ -0,0 +1,23 @@ +.globl _ubox_write_vm + +LDIRVM = 0x005c + +_ubox_write_vm:: + ld hl, #2 + add hl, sp + + ld e, (hl) + inc hl + ld d, (hl) + inc hl + ld c, (hl) + inc hl + ld b, (hl) + inc hl + ld a, (hl) + inc hl + ld h, (hl) + ld l, a + + jp LDIRVM + diff --git a/src/ubox/ubox_wvdp.z80 b/src/ubox/ubox_wvdp.z80 new file mode 100644 index 0000000..90dfc86 --- /dev/null +++ b/src/ubox/ubox_wvdp.z80 @@ -0,0 +1,14 @@ +.globl _ubox_wvdp + +WRITEVDP = 0x0047 + +_ubox_wvdp:: + ld hl, #2 + add hl, sp + + ld c, (hl) + inc hl + ld b, (hl) + call WRITEVDP + ret + |