Browse Source

recipes/sms: add controller support

pull/10/head
Virgil Dupras 5 years ago
parent
commit
ba2804a255
2 changed files with 61 additions and 20 deletions
  1. +3
    -1
      recipes/sms/README.md
  2. +58
    -19
      recipes/sms/glue.asm

+ 3
- 1
recipes/sms/README.md View File

@@ -28,7 +28,9 @@ The binary produced by the Makefile here has been tested on a Genesis +
[Everdrive MD][everdrive] (I haven't built myself a writable cartridge yet).

It is an adaptation of Maxim's (from SMS power) hello world. I converted it to
ZASM. For now, all it does is show "Hello World".
ZASM. It shows a letter in the range of "a" to "i" depending of which button on
controller A is pressed (only detects one button at once). All buttons of the
genesis controller are supported. Shows "i" when no button is pressed.

I've also added the mandatory "TMR SEGA" header at the end of the binary.



+ 58
- 19
recipes/sms/glue.asm View File

@@ -50,34 +50,73 @@ main:
or c
jr nz, .loop2

xor a
ld a, 0b11000000

out (0xbf), a
ld a, 0x78
ld a, 0x81
out (0xbf), a

ld hl, Message
ld bc, MessageEnd-Message
.loop3:
ld a, (hl)
out (0xbe), a
inc hl
dec bc
ld a, b
or c
jr nz, .loop3
ld b, 0x41
jr updateLetter

ld a, 0b11000000
mainloop:
; What we do here is simple. We go though all bits of port A controller
; increasing B each time. As soon as we get a hit, we display that
; letter. Pressed buttons go low.
; This logic below is for the Genesis controller, which is modal. TH is
; an output pin that swiches the meaning of TL and TR. When TH is high
; (unselected), TL = Button B and TR = Button C. When TH is low
; (selected), TL = Button A and TR = Start.
ld a, 0b11111101 ; TH output, unselected
out (0x3f), a
ld b, 0x41 ; a
in a, (0xdc) ; I/O port
and 0b00100000 ; Port A Button C pressed
jr z, updateLetter
inc b ; b
in a, (0xdc)
and 0b00010000 ; Port A Button B pressed
jr z, updateLetter
inc b ; c
in a, (0xdc)
and 0b00001000 ; Port A Right pressed
jr z, updateLetter
inc b ; d
in a, (0xdc)
and 0b00000100 ; Port A Left pressed
jr z, updateLetter
inc b ; e
in a, (0xdc)
and 0b00000010 ; Port A Down pressed
jr z, updateLetter
inc b ; f
in a, (0xdc)
and 0b00000001 ; Port A Up pressed
jr z, updateLetter
ld a, 0b11011101 ; TH output, unselected
out (0x3f), a
inc b ; g
in a, (0xdc)
and 0b00100000 ; Port A Start pressed
jr z, updateLetter
inc b ; h
in a, (0xdc)
and 0b00010000 ; Port A Button A pressed
jr z, updateLetter
inc b ; i
; no button pressed on port A, continue to updateLetter

; Prints letter in B
updateLetter:
xor a
out (0xbf), a
ld a, 0x81
ld a, 0x78
out (0xbf), a

.loop4:
jr .loop4
ld a, b
out (0xbe), a
jr mainloop

Message:
.dw 0x28,0x45,0x4c,0x4c,0x4f,0x00,0x37,0x4f,0x52,0x4c,0x44,0x01
MessageEnd:

PaletteData:
.db 0x00,0x3f


Loading…
Cancel
Save