I am writing an os. I am doing parts in C to get started and then converting to ASM. I use
Code:
to compile. Here is the main part:
Code:
The ifdef Linux is so that my lsp doesn't complain as much.
Anyways here are some main() definitions and their output. https://imgur.com/a/main-c-outputs-4si8NwI
Code:
zcc +sos -crt0=my_crt0.sCode:
__sfr __at 0x10 lcd_command;
__sfr __at 0x11 lcd_data;
#ifdef __linux__
#include <stdint.h>
uint8_t lcd_command, lcd_data;
#endif
#define LCD_6_BIT 0
#define LCD_8_BIT 1
#define LCD_ENABLE 3
#define LCD_DOWN 5
#define LCD_RIGHT 7
#define LCD_ROW 0x80
#define LCD_COL 0x20
#define LCD_CONTRAST 0xC0
typedef unsigned char u8;
u8 *cursor_x = (u8*)0x8000;
u8 *cursor_y = (u8*)0x8001;
#include "font.h"
void lcdDelay() __naked {
__asm
call $+3
nop
ret
__endasm;
}
void lcdSetXY( int x, int y) {
lcd_command = x + LCD_COL;
lcdDelay();
lcd_command = y + LCD_ROW;
lcdDelay();
}
void lcdInit(void) {
lcd_command = LCD_8_BIT;
lcdDelay();
lcd_command = LCD_ENABLE;
lcdDelay();
lcd_command = 0xf0;
lcdDelay();
lcd_command = 0x40;
lcdDelay();
lcd_command = LCD_DOWN;
lcdDelay();
}
int putchar(char c) __z88dk_fastcall {
__asm
ld a,(_cursor_x)
add a,0x20
out (0x10),a
call _lcdDelay
ld a,(_cursor_y)
add a,0x80
out (0x10),a
ld a,l
sub a,0x20
jr c,_putchar_err
ld l,a
ld h,0
add hl,hl
ld de,_CHAR_MAP
add hl,de
ld de,(hl)
ld b,8
_putchar_loop:
ld a,(de)
inc de
out ($11),a
call _lcdDelay
djnz _putchar_loop
ld hl,0
jr _putchar_exit
_putchar_err:
ld hl,1
_putchar_exit:
push hl
ld a,(_cursor_x)
inc a
cp 12
jr c,_putchar_y_noinc
ld a,(_cursor_y)
inc a
ld (_cursor_y),a
xor a
_putchar_y_noinc:
ld (_cursor_x),a
pop hl
__endasm;
}Anyways here are some main() definitions and their output. https://imgur.com/a/main-c-outputs-4si8NwI




