Add instructions to compile C programs.
This commit is contained in:
parent
d00b379598
commit
1d057626e4
20
README.md
20
README.md
@ -17,4 +17,22 @@ Here you can find some utilities to jump start your computer from scratch!
|
|||||||
:warning: Mess with electronics only if you know what you are doing. Beware: you may harm your computer, or even yourself! Everything you do is at your own risk.
|
:warning: Mess with electronics only if you know what you are doing. Beware: you may harm your computer, or even yourself! Everything you do is at your own risk.
|
||||||
|
|
||||||
## How to
|
## How to
|
||||||
- to be written
|
Just some random notes.
|
||||||
|
|
||||||
|
Compile a C program:
|
||||||
|
```sh
|
||||||
|
zcc +z80 -create-app --no-crt -pragma-define:REGISTER_SP=0xC000 -m -o build/main main.c
|
||||||
|
```
|
||||||
|
Important: this is a linker-less and C-runtime-less compilation, so be very very careful what you do.
|
||||||
|
Example minimal starter:
|
||||||
|
```c
|
||||||
|
int entrypoint(void) {
|
||||||
|
__asm
|
||||||
|
ld sp,0xc000
|
||||||
|
__endasm;
|
||||||
|
|
||||||
|
main();
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
43
main.c
Normal file
43
main.c
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
char* const VIDEO_MEMORY = (char* const)0xd000;
|
||||||
|
|
||||||
|
static void vprint(int row, int column, const char* str);
|
||||||
|
static void out(uint8_t ioaddr, uint8_t value);
|
||||||
|
|
||||||
|
int entrypoint() {
|
||||||
|
__asm
|
||||||
|
ld sp,0xc000
|
||||||
|
__endasm;
|
||||||
|
|
||||||
|
vprint(20,10,"hello world");
|
||||||
|
out(0x81, 0x80);
|
||||||
|
vprint(20,15,"aaaaa");
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void out(uint8_t ioaddr, uint8_t value) {
|
||||||
|
__asm
|
||||||
|
ld ix,$0000
|
||||||
|
add ix,sp
|
||||||
|
ld b,(ix + 5)
|
||||||
|
ld c,(ix + 4)
|
||||||
|
out (c),b
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cls(void) {
|
||||||
|
for (int i = 0; i < 2000; ++i) {
|
||||||
|
VIDEO_MEMORY[i] = 0x20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void vprint(int row, int column, const char* str) {
|
||||||
|
char* p = VIDEO_MEMORY + row * 80 + column;
|
||||||
|
while (*str != '\0') {
|
||||||
|
*p++ = *str++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user