mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-03-13 13:32:00 +00:00
Uninitialized reserve
d storage becomes .space in .data segment.
This commit is contained in:
parent
aacfb02375
commit
c8ddbd8edf
@ -125,7 +125,6 @@ TODO
|
||||
* Initial values for reserved tables
|
||||
* give length for tables, must be there for reserved, if no init val
|
||||
* Character tables ("strings" to everybody else)
|
||||
* Put uninitialized `reserve`d data in uninitialized data segment
|
||||
* Addressing modes — indexed mode on more instructions
|
||||
* `jsr (vector)`
|
||||
* `jmp routine`
|
||||
|
@ -31,6 +31,7 @@ Emitting an `if`.
|
||||
= sta screen
|
||||
= rts
|
||||
=
|
||||
= .data
|
||||
= .alias screen 1024
|
||||
|
||||
Emitting a `repeat`.
|
||||
@ -57,8 +58,9 @@ Emitting a `repeat`.
|
||||
= sty screen
|
||||
= rts
|
||||
=
|
||||
= .alias screen 1024
|
||||
= four: .byte 4
|
||||
= .data
|
||||
= .alias screen 1024
|
||||
|
||||
Nested ifs.
|
||||
|
||||
@ -131,9 +133,10 @@ Installing an interrupt handler (at the Kernal level, i.e. with CINV)
|
||||
= jmp (save_cinv)
|
||||
= rts
|
||||
=
|
||||
= .data
|
||||
= .alias screen 1024
|
||||
= .alias cinv 788
|
||||
= save_cinv: .word 0
|
||||
= .space save_cinv 2
|
||||
|
||||
Copy command: immediate -> byte
|
||||
|
||||
@ -146,7 +149,8 @@ Copy command: immediate -> byte
|
||||
= sta position
|
||||
= rts
|
||||
=
|
||||
= position: .byte 0
|
||||
= .data
|
||||
= .space position 1
|
||||
|
||||
Copy command: immediate -> word
|
||||
|
||||
@ -161,7 +165,8 @@ Copy command: immediate -> word
|
||||
= sta position+1
|
||||
= rts
|
||||
=
|
||||
= position: .word 0
|
||||
= .data
|
||||
= .space position 2
|
||||
|
||||
`main` is always emitted first.
|
||||
|
||||
@ -182,4 +187,5 @@ Copy command: immediate -> word
|
||||
= inx
|
||||
= rts
|
||||
=
|
||||
= position: .word 0
|
||||
= .data
|
||||
= .space position 2
|
||||
|
@ -256,8 +256,9 @@ Big test for parsing and emitting instructions.
|
||||
= ora vbyte
|
||||
= rts
|
||||
=
|
||||
= vword: .word 0
|
||||
= vbyte: .byte 0
|
||||
= .data
|
||||
= .space vword 2
|
||||
= .space vbyte 1
|
||||
= .alias table 1024
|
||||
|
||||
| reserve word vword
|
||||
@ -290,8 +291,9 @@ Big test for parsing and emitting instructions.
|
||||
= eor vbyte
|
||||
= rts
|
||||
=
|
||||
= vword: .word 0
|
||||
= vbyte: .byte 0
|
||||
= .data
|
||||
= .space vword 2
|
||||
= .space vbyte 1
|
||||
= .alias table 1024
|
||||
|
||||
| routine main {
|
||||
|
@ -1,4 +1,7 @@
|
||||
.org 0
|
||||
.word $0801
|
||||
.data
|
||||
.org $c000
|
||||
.text
|
||||
.org $0801
|
||||
.byte $10, $08, $c9, $07, $9e, $32, $30, $36, $31, $00, $00, $00
|
||||
|
@ -10,24 +10,30 @@ emitProgram p@(Program decls routines) =
|
||||
let
|
||||
mains = filter (\(Routine name _ _) -> name == "main") routines
|
||||
allElse = filter (\(Routine name _ _) -> name /= "main") routines
|
||||
initializedDecls = filter (\d -> isInitializedDecl d) decls
|
||||
uninitializedDecls = filter (\d -> not $ isInitializedDecl d) decls
|
||||
in
|
||||
emitRoutines p mains ++
|
||||
emitRoutines p allElse ++
|
||||
emitDecls p decls
|
||||
emitDecls p initializedDecls ++
|
||||
(case uninitializedDecls of
|
||||
[] -> ""
|
||||
_ -> ".data\n" ++ emitDecls p uninitializedDecls)
|
||||
|
||||
emitDecls _ [] = ""
|
||||
emitDecls p (decl:decls) =
|
||||
emitDecl p decl ++ "\n" ++ emitDecls p decls
|
||||
|
||||
emitDecl p (Assign name _ addr) = ".alias " ++ name ++ " " ++ (show addr)
|
||||
emitDecl p (Reserve name typ value)
|
||||
| typ == Byte = name ++ ": .byte " ++ val
|
||||
| typ == Word = name ++ ": .word " ++ val
|
||||
| typ == Vector = name ++ ": .word " ++ val
|
||||
where
|
||||
val = case value of
|
||||
(Just v) -> (show v)
|
||||
Nothing -> "0"
|
||||
emitDecl p (Reserve name typ (Just val))
|
||||
| typ == Byte = name ++ ": .byte " ++ (show val)
|
||||
| typ == Word = name ++ ": .word " ++ (show val)
|
||||
| typ == Vector = name ++ ": .word " ++ (show val)
|
||||
|
||||
emitDecl p (Reserve name typ Nothing)
|
||||
| typ == Byte = ".space " ++ name ++ " 1"
|
||||
| typ == Word = ".space " ++ name ++ " 2"
|
||||
| typ == Vector = ".space " ++ name ++ " 2"
|
||||
|
||||
emitDecl p (External name addr) = ".alias " ++ name ++ " " ++ (show addr)
|
||||
emitDecl p d = error (
|
||||
|
@ -102,6 +102,10 @@ isLocationDecl (Assign _ _ _) = True
|
||||
isLocationDecl (Reserve _ _ _) = True
|
||||
isLocationDecl _ = False
|
||||
|
||||
isInitializedDecl (Assign _ _ _) = False
|
||||
isInitializedDecl (Reserve _ _ (Just _)) = True
|
||||
isInitializedDecl (Reserve _ _ Nothing) = False
|
||||
|
||||
declaredLocationNames (Program decls _) =
|
||||
map (getDeclLocationName) (filter (isLocationDecl) decls)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user