Last active
September 17, 2017 16:06
-
-
Save maly/fcb20f5f3b97e6792bdf0f96594ec738 to your computer and use it in GitHub Desktop.
SBC Challenge
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
cpu Z80 | |
memory.ram.from 0x1000 | |
memory.ram.to 0x13ff | |
memory.rom.from 0x0000 | |
memory.rom.to 0x0fff | |
;serial simple | |
;serial.in 1 | |
;serial.out 1 | |
;serial.status 0 | |
;serial.status.available 0x20 | |
;serial.status.ready 0x02 | |
serial 6850 | |
serial.data 0x81 | |
serial.control 0x80 | |
terminal.caps 1 | |
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
cpu C6502 | |
memory.ram.from 0x0000 | |
memory.ram.to 0x0fff | |
memory.rom.from 0xf000 | |
memory.rom.to 0xffff | |
;serial simple | |
;serial.in 1 | |
;serial.out 1 | |
;serial.status 0 | |
;serial.status.available 0x20 | |
;serial.status.ready 0x02 | |
serial 6850 | |
serial.data 0xa001 | |
serial.control 0xa000 | |
serial.map 1 | |
;terminal.caps 1 | |
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
.engine mac6502 | |
ACIA = $A000 | |
ACIACONTROL = ACIA+0 | |
ACIASTATUS = ACIA+0 | |
ACIADATA = ACIA+1 | |
.ORG $FFFC | |
DW reset | |
DW reset | |
.org $f000 | |
RESET: | |
; Nastavíme si ukazatel zásobníku | |
LDX #$FF | |
TXS | |
; Nastavení řídicího registru ACIA | |
LDA #$15 | |
STA ACIAControl | |
; Začínáme vypisovat znaky, Y je ukazatel | |
LDY #0 | |
LOOP: | |
LDA Message,Y ; Načti znak ze zprávy na pozici Y | |
BEQ key ; Jestli je to 0, tak hop! | |
JSR SEROUT ; Jinak zavolej podprogram pro vyslání znaku | |
INY ; Y++ - abychom adresovali další bajt | |
BNE LOOP ; a jestli toho ještě nebylo dost, tak hop na začátek | |
KEY: LDA ACIAStatus ; Přišel nějaký znak? | |
AND #1 ; Bit 0 nám to řekne | |
BEQ KEY ; Nepřišel? Tak to zkusíme znovu, dokud nějaký nepřijde | |
LDA ACIAData | |
SEC | |
ADC #0 | |
JSR serout | |
JMP KEY ; TO JE KONEC!!! :( | |
Message: | |
DB $0C,"My hovercraft is full of eels!",$0D,$0A,$00 | |
; podprogram pro vyslání hodnoty z registru A | |
; přes sériový obvod 6850 na terminál | |
SEROUT: PHA ; Uschováme hodnotu, protože registr A potřebujeme | |
SO_WAIT: LDA ACIAStatus ; Je volno? | |
AND #2 ; Bit 1 nám to řekne | |
BEQ SO_WAIT ; Není? Tak to zkusíme znovu, dokud nebude | |
PLA ; Už je, takže si vrátíme zpět hodnotu z registru A | |
STA ACIAData ; a pošleme ji do 6850 | |
RTS ; už není co na práci, tak se můžeme vrátit |
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
org 0 | |
.engine mac | |
serialctrl = 80h | |
serialdata = 81h | |
di | |
im 1 | |
ld sp, ramtop | |
jr cold | |
;rst 8 | |
push af | |
jp serdy | |
.org 10h | |
;rst 10 | |
ld a,0dh | |
rst 8 | |
ld a,0ah | |
jr 8 | |
cold: | |
; serial init | |
ld a, 15h | |
out (serialctrl),a | |
; begin message | |
warm: | |
ld hl, hello | |
mainstr: | |
call printhl | |
main: | |
call geta | |
jr z, main ;no char, no fun | |
cp 'M' | |
jr z, cMem | |
cp 'G' | |
jr z, cGo | |
; ... | |
ld hl, what | |
jr mainstr | |
cMem: | |
call getaddr | |
cMem1: | |
rst 10h | |
call printaddr | |
ld a,' ' | |
rst 8 | |
ld a,(hl) | |
call printhex | |
ld a,' ' | |
rst 8 | |
ld c,(hl) | |
call getbyte | |
ld (hl),c | |
inc hl | |
ld a,b | |
cp 0dh | |
jr z,cMem1 | |
jp warm | |
cGo: | |
call getaddr | |
jp (hl) | |
cOK: | |
jr main | |
; Service routines | |
getaddr: | |
ld hl, addr | |
call printhl | |
ld hl,0 | |
getaddr1: | |
call geta | |
jr z, getaddr1 | |
rst 8 | |
call ishex | |
ret c | |
call atohex | |
add hl,hl | |
add hl,hl | |
add hl,hl | |
add hl,hl | |
add a,l | |
ld l,a | |
jr getaddr1 | |
getbyte: | |
ld b,0 | |
getb1: | |
call geta | |
jr z, getb1 | |
rst 8 | |
call ishex | |
ld b,a | |
ret c | |
call atohex | |
sla c | |
sla c | |
sla c | |
sla c | |
add a,c | |
ld c,a | |
jr getb1 | |
ishex: | |
cp 'F'+1 | |
jr nc, nothex | |
cp '0' | |
ret | |
nothex: | |
scf | |
ret | |
atohex: | |
sub '0' | |
cp 0ah | |
ret c | |
sub 'A'-'9'-1 | |
ret | |
printhl: ld a,(hl) | |
and 7fh | |
rst 8 | |
ld a,(hl) | |
and 0x80 | |
ret nz | |
inc hl | |
jr printhl | |
printaddr: | |
ld a,h | |
call printhex | |
ld a,l | |
printhex: | |
push af | |
rra | |
rra | |
rra | |
rra | |
and 0fh | |
add a,'0' | |
cp '9'+1 | |
jr c,printhex1 | |
add a,7 | |
printhex1: | |
rst 8 | |
pop af | |
and 0fh | |
add a,'0' | |
cp '9'+1 | |
jr c,printa | |
add a,7 | |
printa: push af | |
serdy: | |
in a,serialctrl | |
and 02 | |
jr z,serdy | |
pop af | |
out serialdata,a | |
ret | |
geta: | |
in a,serialctrl | |
and 01h | |
ret z | |
in a,serialdata | |
or a | |
ret | |
hello: | |
.istr "JESS01 ready", 0x0d, 0x0a | |
what: | |
.istr '?',0dh, 0ah | |
addr: | |
.istr 'Addr:' | |
romend: | |
org 1000h | |
ram: | |
org 1400h - 3 | |
ramtop equ $ | |
lastkey: ds 1 | |
bufa: ds 2 | |
ramend equ $ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment