mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-02-16 15:30:26 +00:00
Indexed indirect. For a relaxing demo.
This commit is contained in:
parent
1cf166f0db
commit
061a1661dd
@ -313,6 +313,17 @@ A comment may appear after each command.
|
||||
| }
|
||||
= True
|
||||
|
||||
A comment may appear after each declaration.
|
||||
|
||||
| reserve byte lives ; fnord
|
||||
| assign byte gdcol 647 ; fnord
|
||||
| external blastoff 4 ; fnnnnnnnnnnnnnnnnfffffffff
|
||||
|
|
||||
| routine main {
|
||||
| nop
|
||||
| }
|
||||
= True
|
||||
|
||||
A program may `reserve` and `assign`.
|
||||
|
||||
| reserve byte lives
|
||||
@ -486,6 +497,7 @@ We cannot absolute-indexed a word.
|
||||
| sta screen
|
||||
| sta screen, x
|
||||
| sta screen, y
|
||||
| sta (screen), y
|
||||
| dec screen
|
||||
| clc
|
||||
| cld
|
||||
@ -530,6 +542,7 @@ We cannot absolute-indexed a word.
|
||||
= sta screen
|
||||
= sta screen, x
|
||||
= sta screen, y
|
||||
= sta (screen), y
|
||||
= dec screen
|
||||
= clc
|
||||
= cld
|
||||
|
@ -1,4 +1,4 @@
|
||||
assign byte table screen 1024
|
||||
assign byte table screen $0400
|
||||
assign byte table screen2 1274
|
||||
assign byte table screen3 1524
|
||||
assign byte table screen4 1774
|
||||
@ -14,11 +14,24 @@ assign byte table vic_bg 53281
|
||||
assign vector cinv 788
|
||||
reserve vector save_cinv
|
||||
|
||||
; TODO: this should be a word
|
||||
|
||||
assign byte pos_lo $fb
|
||||
assign byte pos_hi $fc
|
||||
|
||||
reserve byte value
|
||||
|
||||
reserve byte m_hi
|
||||
reserve byte m_lo
|
||||
reserve byte n_hi
|
||||
reserve byte n_lo
|
||||
|
||||
routine main {
|
||||
lda #5
|
||||
sta vic_border
|
||||
lda #0
|
||||
sta vic_bg
|
||||
jsr reset_pos
|
||||
jsr clear_screen
|
||||
sei {
|
||||
copy vector cinv to save_cinv
|
||||
@ -28,11 +41,59 @@ routine main {
|
||||
repeat bcc { }
|
||||
}
|
||||
|
||||
routine reset_pos {
|
||||
lda #$00
|
||||
sta pos_lo
|
||||
lda #$04
|
||||
sta pos_hi
|
||||
}
|
||||
|
||||
routine our_cinv {
|
||||
inc screen
|
||||
lda value
|
||||
inc value
|
||||
ldy #0
|
||||
sta (pos_lo), y
|
||||
jsr increment_pos
|
||||
jsr compare_pos
|
||||
if beq {
|
||||
jsr reset_pos
|
||||
} else {
|
||||
}
|
||||
jmp save_cinv
|
||||
}
|
||||
|
||||
routine increment_pos {
|
||||
clc
|
||||
lda pos_lo
|
||||
adc #1
|
||||
sta pos_lo
|
||||
lda pos_hi
|
||||
adc #0
|
||||
sta pos_hi
|
||||
}
|
||||
|
||||
routine compare_pos {
|
||||
lda pos_lo
|
||||
sta m_lo
|
||||
lda pos_hi
|
||||
sta m_hi
|
||||
lda #$07
|
||||
sta n_hi
|
||||
lda #$e8
|
||||
sta n_lo
|
||||
jsr compare_16_bit
|
||||
}
|
||||
|
||||
routine compare_16_bit {
|
||||
lda m_hi
|
||||
cmp n_hi
|
||||
if beq {
|
||||
lda m_lo
|
||||
cmp n_lo
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
routine clear_screen {
|
||||
ldy #0
|
||||
repeat bne {
|
||||
|
@ -60,6 +60,8 @@ emitInstr p r (COPYINDEXED A (NamedLocation label) Y) = "sta " ++ label ++ ", y"
|
||||
emitInstr p r (COPYINDEXED (NamedLocation label) A X) = "lda " ++ label ++ ", x"
|
||||
emitInstr p r (COPYINDEXED (NamedLocation label) A Y) = "lda " ++ label ++ ", y"
|
||||
|
||||
emitInstr p r (COPYINDIRECTINDEXED A (NamedLocation label) Y) = "sta (" ++ label ++ "), y"
|
||||
|
||||
emitInstr p r (CMP A (NamedLocation label)) = "cmp " ++ label
|
||||
emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
|
||||
emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label
|
||||
|
@ -57,6 +57,7 @@ data Branch = BCC | BCS | BEQ | BMI | BNE | BPL | BVC | BVS
|
||||
data Instruction = PUT StorageLocation DataValue
|
||||
| COPY StorageLocation StorageLocation
|
||||
| COPYINDEXED StorageLocation StorageLocation StorageLocation
|
||||
| COPYINDIRECTINDEXED StorageLocation StorageLocation StorageLocation
|
||||
| CMPIMM StorageLocation DataValue
|
||||
| CMP StorageLocation StorageLocation
|
||||
| ADDIMM StorageLocation DataValue
|
||||
|
@ -10,7 +10,7 @@ import SixtyPical.Model
|
||||
|
||||
{-
|
||||
|
||||
Toplevel := {Decl} {Routine}.
|
||||
Toplevel := {Decl [Comment]} {Routine}.
|
||||
Decl := "reserve" StorageType LocationName
|
||||
| "assign" StorageType LocationName Address
|
||||
| "external" RoutineName Address.
|
||||
@ -37,10 +37,16 @@ Branch := "bcc" | "bcs" | "beq" | "bmi" | "bne" | "bpl" | "bvc" | "bvs".
|
||||
|
||||
toplevel :: Parser Program
|
||||
toplevel = do
|
||||
decls <- many (try assign <|> try reserve <|> try external)
|
||||
decls <- many decl
|
||||
routines <- many routine
|
||||
return $ Program decls routines
|
||||
|
||||
decl :: Parser Decl
|
||||
decl = do
|
||||
d <- (try assign <|> try reserve <|> try external)
|
||||
optional comment
|
||||
return d
|
||||
|
||||
reserve :: Parser Decl
|
||||
reserve = do
|
||||
string "reserve"
|
||||
@ -126,6 +132,32 @@ index = do
|
||||
"x" -> X
|
||||
"y" -> Y
|
||||
|
||||
data Directness = Direct LocationName
|
||||
| Indirect LocationName
|
||||
deriving (Ord, Show, Eq)
|
||||
|
||||
indirect_location :: Parser Directness
|
||||
indirect_location = do
|
||||
string "("
|
||||
spaces
|
||||
l <- locationName
|
||||
string ")"
|
||||
spaces
|
||||
return $ Indirect l
|
||||
|
||||
direct_location :: Parser Directness
|
||||
direct_location = do
|
||||
l <- locationName
|
||||
return $ Direct l
|
||||
|
||||
directness_location = (try indirect_location) <|> direct_location
|
||||
|
||||
indirect_indexed :: (Directness -> [StorageLocation] -> Instruction) -> Parser Instruction
|
||||
indirect_indexed f = do
|
||||
d <- directness_location
|
||||
indexes <- many index
|
||||
return $ f d indexes
|
||||
|
||||
absolute_indexed :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction
|
||||
absolute_indexed f = do
|
||||
l <- locationName
|
||||
@ -305,10 +337,11 @@ sta :: Parser Instruction
|
||||
sta = do
|
||||
string "sta"
|
||||
spaces
|
||||
absolute_indexed gen
|
||||
indirect_indexed gen
|
||||
where
|
||||
gen l [] = COPY A (NamedLocation l)
|
||||
gen l [reg] = COPYINDEXED A (NamedLocation l) reg
|
||||
gen (Direct l) [] = COPY A (NamedLocation l)
|
||||
gen (Direct l) [reg] = COPYINDEXED A (NamedLocation l) reg
|
||||
gen (Indirect l) [reg] = COPYINDIRECTINDEXED A (NamedLocation l) reg
|
||||
|
||||
stx :: Parser Instruction
|
||||
stx = do
|
||||
|
Loading…
x
Reference in New Issue
Block a user