1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-02 18:41:35 +00:00

It generates something Ophis can stomach, now.

This commit is contained in:
Cat's Eye Technologies 2014-04-01 14:59:28 +01:00
parent efc79edbc0
commit 0f71bcd7d2
2 changed files with 11 additions and 7 deletions

View File

@ -97,8 +97,6 @@ TODO
* Parse HEX values like $40A3
* Full machine model
* Check before analyzing
* Check, analyze, generate
* Addressing modes; rename instructions to match
Tests
@ -200,15 +198,16 @@ No duplicate declarations.
| ldy score
| tya
| }
= (decl)
= (decl)
= .org $c000
= score: .word 0
= .alias screen 4000
= main:
= lda screen
= tax
= tay
= cmp score
= (instr)
= ldx score
= txa
= (instr)
= ldy score
= tya
= rts

View File

@ -5,6 +5,7 @@ module SixtyPical.Emitter where
import SixtyPical.Model
emitProgram p@(Program decls routines) =
".org $c000\n" ++
emitDecls p decls ++
emitRoutines p routines
@ -12,7 +13,9 @@ emitDecls _ [] = ""
emitDecls p (decl:decls) =
emitDecl p decl ++ "\n" ++ emitDecls p decls
emitDecl p _ = "(decl)"
emitDecl p (Assign name _ addr) = ".alias " ++ name ++ " " ++ (show addr)
emitDecl p (Reserve name Byte) = name ++ ": .byte 0"
emitDecl p (Reserve name Word) = name ++ ": .word 0"
emitRoutines _ [] = ""
emitRoutines p (rout:routs) =
@ -26,6 +29,8 @@ emitInstrs p r (instr:instrs) =
" " ++ emitInstr p r instr ++ "\n" ++ emitInstrs p r instrs
emitInstr p r (LOAD A label) = "lda " ++ label
emitInstr p r (LOAD X label) = "ldx " ++ label
emitInstr p r (LOAD Y label) = "ldy " ++ label
emitInstr p r (CMP A label) = "cmp " ++ label
emitInstr p r (COPY A X) = "tax"