Compare commits

...

2 Commits

7 changed files with 162 additions and 164 deletions

2
README
View File

@ -12,6 +12,6 @@ layout ./kip* -- sdl2-based emulator
./x/ -- examples
patches, questions, comments welcome: kitty+kip@piapiac.org
or you can open issues & pull requests: https://codeberg.org/kitty/kip
or you can open issues & pull requests: https://git.vern.cc/kcp/kip
browse the updated git repository: https://git.cro.wtf/kip.git
more examples: https://git.cro.wtf/kcp/mow.git

14
d/kip
View File

@ -1,14 +0,0 @@
KIP COMPUTER
DEVICES
for now, see ../kip-io.def
extensive documentation here is TODO
INTERRUPT VECTOR TABLE
0x00 -- Display VSYNC
0x04 -- Mouse Down
0x08 -- Mouse Up
0x0c -- Keyboard Down
0x10 -- Keyboard Up

41
d/kip-as.md Normal file
View File

@ -0,0 +1,41 @@
---
kip manual: as
...
# Kip kmx20 Assembler
This document is heavily incomplete; it is work-in-progress effort.
# Syntax
## Tokens
Tokens are generally split by whitespace.
## Colours
A token has a type, or 'colour' based on its first character.
| Char | Description |
|------|-------------|
|`{` | Comment. All text until the next `}` is ignored. |
|`"` | String literal. This is included in the resultant binary literally. *(e.g. "meow" puts the string "meow" in the output binary)* |
|`#` | Hexadecimal literal. The amount of bytes included in the output binary is either 1, 2, or 4 based on length. Numbers are little-endian. *(e.g. #00 outputs a byte, #0000 half a word, and #00000000 a full word)* |
|`:` | Label definition |
|`@` | 32-bit reference to label *(e.g. `pw @label ju` would jump to the label defined by `:label`)* |
|`^` | 8-bit relative reference to label *(e.g. `pr ^label ju` would jump to the label defined by :label)* |
|`!` | Macro definition. words that follow are included in macro until `;` *(e.g. `!meow #0000 ;`)* |
|```` | Macro reference. *(e.g. `meow` (from above) will now output 2 bytes of `0s`)* |
|`-` | Assembler built-in. these can take some amount of arguments.
Without colour, it is treated as an instruction. See [kmx20](./kmx20.md) for ISA documentation.
Instructions can additionally have the following prefixes, which may affect the resulting opcode.
- `~` F flag (flip stack manipulations from data <-> return stacks)
- `$` K flag (keep lhs on rhs)
## Builtins
- `-org #` Sets the origin for labels. The first -org is the entry point of the output file. Output ROMs are inserted at #100 in the CPU's memory, so you should generally start a program off with -org #0100.
- `-res #` Reserves some bytes in the output binary. Basically same as -org but relative to current address.
- `-emb "` Embed a file into the output binary.
- `-inc "` Include a file literally. Gets assembled into the output binary.

19
d/kip.md Normal file
View File

@ -0,0 +1,19 @@
---
title: kip manual: kip computer
...
# Kip Computer
## Devices
For now, see `../kip-io.def` in the git repository. Extensive documentation here is TODO
## Interrupt Vector Table
| Port | Description |
|------|--------------------|
|`0x00`| Display VSYNC |
|`0x04`| Mouse Down |
|`0x08`| Mouse Up |
|`0x0c`| Keyboard Down |
|`0x10`| Keyboard Up |

91
d/kmm32
View File

@ -1,91 +0,0 @@
KMM32 CPU
This document is heavily incomplete and may be at parts incorrect. It is a
work-in-progress effort.
HARDWARE REGISTERS
The KMM32 has 3 hardware registers,
ip -- (Word) Instruction pointer
dp -- (Byte) Data Stack Pointer
rp -- (Byte) Return Stack Pointer
BUSSES
The KMM32 has 2 data busses.
mem -- Memory Bus
Byte-addressed
Where data is to be read and writ
+---0x00000---+ <-- Interrupt Vector Table
| (rwx) |
+---0x00100---+ <-- Boot
| (rwx) | This is where the CPU resets to,
| | and where the emulator puts
| | loaded ROMs.
. .
. .
| |
+---0x40000---+ <-- Data Stack
| (rw-) | Word-addressed by `dp
+---0x40400---+ <-- Return Stack
| (rw-) | Word-addressed by `rp
+---0x40800---+
io -- Input/Output Bus
Word-addressed
Peripherals are directly connected to this bus
(see ./kip for kip computer i/o)
INSTRUCTIONS
Opcodes take 1 byte in memory.
Each binary digit corresponds to:
UFOOOOOO
||O: Opcode
|F: Flip return and data stacks
| (eg 01000010 will put the next byte in memory onto the return stack)
K: Keep left hand operands
(eg (a--n) below becomes (a--a n))
OPCODES
np (--) no-op
ex (--) halt execution
pb (--n) puts the next byte (8 bits) in memory onto the stack
ph (--n) ^ same but next half-word (16 bits)
pw (--n) ^ same but next word (32 bits)
pr (--n) puts ip+the next byte plus onto the stack
fb (a--n) fetches a byte from address `a and puts it onto the stack
fh (a--n) ^ same but with half-word
fw (a--n) ^ same but with word
mb (n a--) truncate stack item `n into a byte and put it in memory address `a
mh (n a--) ^ same but with half-word
mw (n a--) ^ same but with word
io (n p--) move cell `n to io port `p
ii (p--n) gets cell from io port `p and pushes it onto the stack
ss (n-~n) move cell from data stack to return stack
dr (n--) drop item from data stack
sw (n m--m n) swap items
du (n--n n) duplicate item on data stack
ov (n m--n m n) bring second item on data stack over
ad (n m--n+m) add
su (n m--n-m) subtract
mu (n m--n*m) multiply
di (n m--n/m n%m)div rem
an (n m--n&m) bitwise and
or (n m--n|m) bitwise or
xr (n m--n^m) bitwise xor
sl (n m--n<<m) bitwise shift left
sr (n m--n>>m) bitwise shift right
sa (n m--n>>>m) bitwise arithmetic shift right
eq (n m--n==m) logical equals
lt (n m--n<m) logical less than
gt (n m--n>m) logical greater than
no (n--!n) logical not
ju (a--) jump to address `a
jc (n a--) jump to address `a if `n!=0
ca (a-~r) push ip onto return stack, then jump to address `a
cc (n a-~r) push ip onto return stack and jump to address `a if `n!=0

View File

@ -1,58 +0,0 @@
KMM32 ASSEMBLER
This document is heavily incomplete and may be at parts incorrect It is a
work-in-progress effort.
SYNTAX
TOKENS
Tokens are generally split by whitespace, but 1 special case is made for
"strings", which can contain whitespace inside.
Tokens are similar to words in forths.
COLOURS
A token has a type, or 'colour' based on its first character.
{ - Comment; all text until the next `} is ignored.
" - String literal; this is included in the resultant binary literally.
EG. "meow" puts "meow" in the output binary
# - Hexadecimal literal; the amount of bytes included in the output binary
is either 1, 2, or 4 based on length. Numbers are little-endian.
EG. #00 outputs a byte, #0000 a half word, and #00000000 a full word
: - Label definition
@ - 32-bit reference to label
EG. `pw @label ju` would jump to the label defined by :label
^ - 8-bit relative reference to label
EG. `pr ^label ju` would jump to the label defined by :label
! - Macro definition; words that follow are included in macro until `;
EG: !meow #0000 ;
` - Macro reference;
EG. `meow (from above) will now output 2 bytes of 0s
- - Assembler built-in; these can take some amount of arguments.
Otherwise, it is treated as an instruction. (See d/kmm32 for ISA documentation)
Instructions can additionally have the following prefixes, which may affect the
resulting opcode:
~ - F flag (flip stack manipulations from data <-> return stacks)
$ - K flag (keep lhs on rhs)
BUILTINS
Colour of arguments denoted with first character.
-org #; Sets the origin for labels. The first -org is the entry point of the
output file. Output ROMs are inserted at #100 in the CPU's memory,
so you should generally start a program off with -org #0100.
-res #; Reserves some bytes in the output binary. Basically same as -org but
relative to current address.
-emb "; Embed a file into the output binary
-inc "; Include a file literally. Gets assembled into the output binary.

101
d/kmx20.md Normal file
View File

@ -0,0 +1,101 @@
---
title: kip manual: kmx20
...
# kmx20 cpu
This document is heavily incomplete. It is a work-in-progress effort.
## Hardware registers
The kmx20 has 3 hardware registers,
- `ip` `Word` Instruction pointer
- `dp` `Byte` Data Stack Pointer
- `rp` `Byte` Return Stack Pointer
## Busses
The kmx20 has 2 data busses.
- mem
- Memory bus
- Byte-addressed
- Where data is to be read and writ
```
+---0x00000---+ <-- Interrupt Vector Table
| (rwx) |
+---0x00100---+ <-- Boot
| (rwx) | This is where the CPU resets to,
| | and where the emulator puts
| | loaded ROMs.
. .
. .
. .
| |
+---0x40000---+ <-- Data Stack
| (rw-) | Word-addressed by `dp
+---0x40400---+ <-- Return Stack
| (rw-) | Word-addressed by `rp
+---0x40800---+
```
- io
- Input/Output Bus
- Word-addressed
- Peripherals are directly connected to this bus
- See [kip.md](./kip.md) for kip computer i/o
## Instructions
Instructions take 1 byte in memory. Each binary digit corresponds to
```
XFOOOOOO
|||O: Opcode
||F: Flip return and data stacks
|| (eg 01000010 will put the next byte in memory onto the return stack)
|K: Keep left hand operands
| (eg (a--n) below becomes (a--a n))
|X: Unused
```
## Opcodes
| Op | Stack effect | Description |
|----|--------------|-----------------------------------------------------------------------------|
|`np`|`--` | no-op |
|`ex`|`--` | halt execution |
|`pb`|`--n` | puts the next byte (8 bits) in memory onto the stack |
|`ph`|`--n` | ^ same but next half-word (16 bits) |
|`pw`|`--n` | ^ same but next word (32 bits) |
|`pr`|`--n` | puts ip+the next byte plus onto the stack |
|`fb`|`a--n` | fetches a byte from address \`a and puts it onto the stack |
|`fh`|`a--n` | ^ same but with half-word |
|`fw`|`a--n` | ^ same but with word |
|`mb`|`n a--` | truncate stack item \`n into a byte and put it in memory address \`a |
|`mh`|`n a--` | ^ same but with half-word |
|`mw`|`n a--` | ^ same but with word |
|`io`|`n p--` | move cell \`n to io port \`p |
|`ii`|`p--n` | gets cell from io port \`p and pushes it onto the stack |
|`ss`|`n-~n` | move cell from data stack to return stack |
|`dr`|`n--` | drop item from data stack |
|`sw`|`n m--m n` | swap items |
|`du`|`n--n n` | duplicate item on data stack |
|`ov`|`n m--n m n` | bring second item on data stack over |
|`ad`|`n m--n+m` | add |
|`su`|`n m--n-m` | subtract |
|`mu`|`n m--n*m` | multiply |
|`di`|`n m--n/m n%m`| div rem |
|`an`|`n m--n&m` | bitwise and |
|`or`|`n m--n|m` | bitwise or |
|`xr`|`n m--n^m` | bitwise xor |
|`sl`|`n m--n<<m` | bitwise shift left |
|`sr`|`n m--n>>m` | bitwise shift right |
|`sa`|`n m--n>>>m` | bitwise arithmetic shift right |
|`eq`|`n m--n==m` | logical equals |
|`lt`|`n m--n<m` | logical less than |
|`gt`|`n m--n>m` | logical greater than |
|`no`|`n--!n` | logical not |
|`ju`|`a--` | jump to address `a |
|`jc`|`n a--` | jump to address `a if `n!=0 |
|`ca`|`a-~r` | push ip onto return stack, then jump to address `a |
|`cc`|`n a-~r` | push ip onto return stack and jump to address `a if `n!=0 |