Skip to content

Commit

Permalink
Make a hexes library for printing to screen
Browse files Browse the repository at this point in the history
  • Loading branch information
xymostech committed Apr 13, 2014
1 parent d5f0935 commit f5b7f0c
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ continue: disk.flp
%.o: %.asm
nasm -f elf32 -o $@ $<

os.bin: os.o main.o pic.o io.o floppy.o dma.o
os.bin: os.o main.o pic.o io.o floppy.o dma.o keyboard.o hexes.o
ld -o $@ $^ --oformat binary -mi386linux -Ttext -0x20

disk.flp: boot.bin os.bin
Expand Down
4 changes: 2 additions & 2 deletions floppy.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ volatile int irq6_done = 0;

void _irq6_handler() {
irq6_done = 1;
*(char*)(0xb800a) = 0x4C;
hexes_write_char('F', 0, 5);
}

void wait_for_rqm() {
Expand Down Expand Up @@ -97,7 +97,7 @@ void floppy_init() {
motoron();
recalibrate();

*(char*)(0xb800c) = 0x4C;
hexes_write_char('I', 0, 6);

dma_setup_floppy();
}
Expand Down
1 change: 1 addition & 0 deletions floppy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "pic.h"
#include "dma.h"
#include "hexes.h"

void _irq6_handler();
void floppy_init();
Expand Down
25 changes: 25 additions & 0 deletions hexes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "hexes.h"

void hexes_move_cursor(int row, int col) {
uint16_t position = row * 80 + col;

outb(0x3D4, 0x0F);
outb(0x3D5, position & 0xFF);

outb(0x3D4, 0x0E);
outb(0x3D5, (position >> 8) & 0xFF);
}

void hexes_write_char(uint8_t character, int row, int col) {
uint16_t position = row * 80 + col;

*(char*)(0xb8000 + position * 2) = character;
}

void hexes_write_string(char *str, int row, int col) {
while(*str) {
hexes_write_char(*str, row, col);
col++;
str++;
}
}
11 changes: 11 additions & 0 deletions hexes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef HEXES_H
#define HEXES_H

#include "types.h"
#include "io.h"

void hexes_move_cursor(int row, int col);
void hexes_write_char(uint8_t character, int row, int col);
void hexes_write_string(char *str, int row, int col);

#endif
27 changes: 27 additions & 0 deletions keyboard.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "keyboard.h"

uint8_t last_keycode = 0;

void _keyboard_int(int keycode) {
last_keycode = keycode;
hexes_write_char(get_last_key(), 0, 2);
}

uint8_t key_translate[] = {
0x00, 0x00, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, // 0x00
0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x7F, 0x09, // 0x08
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, // 0x10
0x6F, 0x70, 0x00, 0x00, 0x0A, 0x00, 0x61, 0x73, // 0x18
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x00, // 0x20
0x00, 0x00, 0x00, 0x00, 0x7A, 0x78, 0x63, 0x76, // 0x28
0x62, 0x6E, 0x6D, 0x00, 0x2E, 0x2F, 0x00, 0x00, // 0x30
0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // 0x38
};

uint8_t get_last_key() {
if (last_keycode < 0xFF) {
return key_translate[last_keycode];
} else {
return 0x00;
}
}
10 changes: 10 additions & 0 deletions keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H

#include "types.h"
#include "hexes.h"

uint8_t get_last_key();
void _keyboard_int(int keycode);

#endif
40 changes: 18 additions & 22 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include "pic.h"
#include "floppy.h"
#include "dma.h"
#include "hexes.h"

void _keyboard_int(int keycode) {
*(char*)(0xb8004) = keycode;
}

void print_number(uint16_t x, int offset) {
char buf[4];
void print_number(uint16_t x, int row, int col) {
char buf[5];
char ch;
int c;

Expand All @@ -22,15 +19,16 @@ void print_number(uint16_t x, int offset) {
x >>= 4;
}

for (c = 0; c < 4; c++) {
*(char*)(0xb8000 + c*2 + offset) = buf[c];
}
buf[4] = 0;
hexes_write_string(buf, row, col);
}

void clear_screen() {
int i;
for (i = 0; i < 2000; i++) {
*(char*)(0xb8000 + i * 2) = 0x20;
int i, j;
for (i = 0; i < 25; i++) {
for (j = 0; j < 80; j++) {
hexes_write_char(' ', i, j);
}
}
}

Expand All @@ -47,17 +45,15 @@ __attribute__((naked)) void _main() {

floppy_read(buffer, 0, 0, 1);

buffer[0] = 0xab;

floppy_write(buffer, 0, 0, 1);
floppy_read(buffer, 0, 0, 1);
print_number(buffer[0], 0, 10);
print_number(buffer[1], 0, 14);
print_number(buffer[2], 0, 18);
print_number(buffer[3], 0, 22);
print_number(buffer[4], 0, 26);

print_number(buffer[0], 0x10);
print_number(buffer[1], 0x18);
print_number(buffer[2], 0x20);
print_number(buffer[3], 0x28);
print_number(buffer[4], 0x30);
hexes_move_cursor(0, 0);
hexes_write_char('(', 0, 0);
hexes_write_char(':', 0, 1);

*(int*)(0xb8000) = 0x203a2028;
while (1) {}
}

0 comments on commit f5b7f0c

Please sign in to comment.