1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-09-29 08:57:04 +00:00

Indexed indirect. For a relaxing demo.

This commit is contained in:
Cat's Eye Technologies 2014-04-02 17:48:44 +01:00
parent 1cf166f0db
commit 061a1661dd
5 changed files with 117 additions and 7 deletions

View File

@ -313,6 +313,17 @@ A comment may appear after each command.
| } | }
= True = 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`. A program may `reserve` and `assign`.
| reserve byte lives | reserve byte lives
@ -486,6 +497,7 @@ We cannot absolute-indexed a word.
| sta screen | sta screen
| sta screen, x | sta screen, x
| sta screen, y | sta screen, y
| sta (screen), y
| dec screen | dec screen
| clc | clc
| cld | cld
@ -530,6 +542,7 @@ We cannot absolute-indexed a word.
= sta screen = sta screen
= sta screen, x = sta screen, x
= sta screen, y = sta screen, y
= sta (screen), y
= dec screen = dec screen
= clc = clc
= cld = cld

View File

@ -1,4 +1,4 @@
assign byte table screen 1024 assign byte table screen $0400
assign byte table screen2 1274 assign byte table screen2 1274
assign byte table screen3 1524 assign byte table screen3 1524
assign byte table screen4 1774 assign byte table screen4 1774
@ -14,11 +14,24 @@ assign byte table vic_bg 53281
assign vector cinv 788 assign vector cinv 788
reserve vector save_cinv 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 { routine main {
lda #5 lda #5
sta vic_border sta vic_border
lda #0 lda #0
sta vic_bg sta vic_bg
jsr reset_pos
jsr clear_screen jsr clear_screen
sei { sei {
copy vector cinv to save_cinv copy vector cinv to save_cinv
@ -28,11 +41,59 @@ routine main {
repeat bcc { } repeat bcc { }
} }
routine reset_pos {
lda #$00
sta pos_lo
lda #$04
sta pos_hi
}
routine our_cinv { 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 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 { routine clear_screen {
ldy #0 ldy #0
repeat bne { repeat bne {

View File

@ -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 X) = "lda " ++ label ++ ", x"
emitInstr p r (COPYINDEXED (NamedLocation label) A Y) = "lda " ++ label ++ ", y" 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 A (NamedLocation label)) = "cmp " ++ label
emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label emitInstr p r (CMP X (NamedLocation label)) = "cpx " ++ label
emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label emitInstr p r (CMP Y (NamedLocation label)) = "cpy " ++ label

View File

@ -57,6 +57,7 @@ data Branch = BCC | BCS | BEQ | BMI | BNE | BPL | BVC | BVS
data Instruction = PUT StorageLocation DataValue data Instruction = PUT StorageLocation DataValue
| COPY StorageLocation StorageLocation | COPY StorageLocation StorageLocation
| COPYINDEXED StorageLocation StorageLocation StorageLocation | COPYINDEXED StorageLocation StorageLocation StorageLocation
| COPYINDIRECTINDEXED StorageLocation StorageLocation StorageLocation
| CMPIMM StorageLocation DataValue | CMPIMM StorageLocation DataValue
| CMP StorageLocation StorageLocation | CMP StorageLocation StorageLocation
| ADDIMM StorageLocation DataValue | ADDIMM StorageLocation DataValue

View File

@ -10,7 +10,7 @@ import SixtyPical.Model
{- {-
Toplevel := {Decl} {Routine}. Toplevel := {Decl [Comment]} {Routine}.
Decl := "reserve" StorageType LocationName Decl := "reserve" StorageType LocationName
| "assign" StorageType LocationName Address | "assign" StorageType LocationName Address
| "external" RoutineName Address. | "external" RoutineName Address.
@ -37,10 +37,16 @@ Branch := "bcc" | "bcs" | "beq" | "bmi" | "bne" | "bpl" | "bvc" | "bvs".
toplevel :: Parser Program toplevel :: Parser Program
toplevel = do toplevel = do
decls <- many (try assign <|> try reserve <|> try external) decls <- many decl
routines <- many routine routines <- many routine
return $ Program decls routines return $ Program decls routines
decl :: Parser Decl
decl = do
d <- (try assign <|> try reserve <|> try external)
optional comment
return d
reserve :: Parser Decl reserve :: Parser Decl
reserve = do reserve = do
string "reserve" string "reserve"
@ -126,6 +132,32 @@ index = do
"x" -> X "x" -> X
"y" -> Y "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 :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction
absolute_indexed f = do absolute_indexed f = do
l <- locationName l <- locationName
@ -305,10 +337,11 @@ sta :: Parser Instruction
sta = do sta = do
string "sta" string "sta"
spaces spaces
absolute_indexed gen indirect_indexed gen
where where
gen l [] = COPY A (NamedLocation l) gen (Direct l) [] = COPY A (NamedLocation l)
gen l [reg] = COPYINDEXED A (NamedLocation l) reg gen (Direct l) [reg] = COPYINDEXED A (NamedLocation l) reg
gen (Indirect l) [reg] = COPYINDIRECTINDEXED A (NamedLocation l) reg
stx :: Parser Instruction stx :: Parser Instruction
stx = do stx = do