Permalink
Browse files

finetuning memory layout setup

  • Loading branch information...
1 parent 696f916 commit 853f7a5244e814a4609e9dc788a2075160679a69 orlof committed Jan 6, 2013
Showing with 89 additions and 71 deletions.
  1. +9 −6 data.dasm16
  2. +26 −8 defs.dasm16
  3. +2 −2 edit.dasm16
  4. +10 −19 floppy.dasm16
  5. +19 −13 integer.dasm16
  6. +2 −2 memory.dasm16
  7. +17 −17 screen.dasm16
  8. +4 −4 stdlib.dasm16
View
@@ -14,15 +14,18 @@
;----------------------------------------------------------------
:current_screen dat screen_first
-:screen_first dat 0xd000, 0xd180, 0xd000
- dat 0xd180, 0xd300, 0xd180
-:screen_last dat 0xd300, 0xd480, 0xd300
+:screen_first dat MEM_SCREEN_START, MEM_SCREEN_START + 0x180, MEM_SCREEN_START
+ dat MEM_SCREEN_START + 0x180, MEM_SCREEN_START + 0x300, MEM_SCREEN_START + 0x180
+:screen_last dat MEM_SCREEN_START + 0x300, MEM_SCREEN_START + 0x480, MEM_SCREEN_START + 0x300
;----------------------------------------------------------------
; GLOBAL FD VARIABLES
;----------------------------------------------------------------
-
+; current file status
+:file_position dat 0
+:file_buffer_position dat 0
+:file_current_sector dat 0
;----------------------------------------------------------------
; RANDOM NUMBER GENERATORS
@@ -45,9 +48,9 @@
; GLOBAL HEAP MANAGEMENT VARIABLES
;----------------------------------------------------------------
:heap_counter DAT 0
-:heap_free_start DAT HEAP_START
+:heap_free_start DAT MEM_HEAP_START
-:heap_handle_start DAT HEAP_END
+:heap_handle_start DAT MEM_HEAP_END
:heap_handle_head DAT 0
:heap_handle_tail DAT heap_handle_head - HANDLE_NEXT
:heap_handle_free DAT 0
View
@@ -1,17 +1,35 @@
;----------------------------------------------------------------
-; CONSTANTS
+; MEMORY LAYOUT
;----------------------------------------------------------------
-#define TRUE 1
-#define FALSE 0
+#define MEM_CODE_SIZE 0x6000
+#define MEM_HEAP_SIZE 0x8000
+#define MEM_SCREEN_BUFFER_SIZE 0x480
+#define MEM_FLOPPY_BUFFER_SIZE 0x200
+
+#define MEM_HEAP_START MEM_CODE_SIZE
+#define MEM_HEAP_END MEM_HEAP_START + MEM_HEAP_SIZE
-#define HEAP_START 0x6000
-#define HEAP_END 0xd000
+#define MEM_SCREEN_START MEM_HEAP_END
+#define MEM_SCREEN_END MEM_SCREEN_START + MEM_SCREEN_BUFFER_SIZE
+#define MEM_FLOPPY_START MEM_SCREEN_END
+#define MEM_FLOPPY_END MEM_FLOPPY_START + MEM_FLOPPY_BUFFER_SIZE
+
+
+;----------------------------------------------------------------
+; PARAMETERS
+;----------------------------------------------------------------
#define EDIT_BUFFER_SIZE 0x0400
#define HEAP_GC_TRIGGER 25
#define FLOAT_PRECISION 2
; 2*16=32 bits for mantissa
+;----------------------------------------------------------------
+; CONSTANTS
+;----------------------------------------------------------------
+#define TRUE 1
+#define FALSE 0
+
#define FLOAT_CATEGORY_NAN 0x0000
#define FLOAT_CATEGORY_PINF 0x0400
#define FLOAT_CATEGORY_PNUM 0x0200
@@ -160,9 +178,9 @@
; uint16 *cursor;
; }
#define SIZEOF_SCREEN 3
-#define SCREEN_START 0
-#define SCREEN_END 1
-#define SCREEN_CURSOR 2
+#define SCREEN__START 0
+#define SCREEN__END 1
+#define SCREEN__CURSOR 2
; struct file_handle {
; struct handle *first_sector;
View
@@ -215,12 +215,12 @@
;----------------------------------------------------------------
set a, [current_screen]
set i, [win_start]
- set j, [a + SCREEN_START]
+ set j, [a + SCREEN__START]
:edit_win_draw_loop
jsr edit_line_draw
- ifl j, [a + SCREEN_END]
+ ifl j, [a + SCREEN__END]
set pc, edit_win_draw_loop
set pc, pop
View
@@ -5,22 +5,13 @@
; item load(str)
; del(str)
-; memory buffer
-#define FILE_BUFFER_START 49152
-#define FILE_BUFFER_END 49664
-
; these defines are only foor mbr
-#define FILE_FREE_HEAD FILE_BUFFER_START
-#define FILE_FREE_TAIL FILE_BUFFER_START + 1
-#define FILE_DIR_SECTOR FILE_BUFFER_START + 2
+#define FILE_FREE_HEAD MEM_FLOPPY_START
+#define FILE_FREE_TAIL MEM_FLOPPY_START + 1
+#define FILE_DIR_SECTOR MEM_FLOPPY_START + 2
; all other sectors
-#define FILE_NEXT_SECTOR FILE_BUFFER_START
-
-; current file status
-:file_position dat 0
-:file_buffer_position dat 0
-:file_current_sector dat 0
+#define FILE_NEXT_SECTOR MEM_FLOPPY_START
;----------------------------------------------------------------
; struct handle *file__dir__read(void)
@@ -396,7 +387,7 @@
;----------------------------------------------------------------
:file__write_word
;----------------------------------------------------------------
- ife [file_buffer_position], FILE_BUFFER_END
+ ife [file_buffer_position], MEM_FLOPPY_END
set pc, file__write_word__add_to_buffer
jsr file__write_sector
@@ -415,7 +406,7 @@
;----------------------------------------------------------------
:file__read_word
;----------------------------------------------------------------
- ife [file_buffer_position], FILE_BUFFER_END
+ ife [file_buffer_position], MEM_FLOPPY_END
jsr file__next_sector
set c, [file_buffer_position]
@@ -436,7 +427,7 @@
set a, 3
set x, [file_current_sector]
- set y, FILE_BUFFER_START
+ set y, MEM_FLOPPY_START
hwi [floppy]
set a, 0
@@ -458,7 +449,7 @@
set a, 2
set x, [file_current_sector]
- set y, FILE_BUFFER_START
+ set y, MEM_FLOPPY_START
hwi [floppy]
set a, 0
@@ -473,13 +464,13 @@
:file__next_sector
;----------------------------------------------------------------
; get the next sector number
- set [file_current_sector], [FILE_BUFFER_START]
+ set [file_current_sector], [MEM_FLOPPY_START]
; read the sector to memory buffer
jsr file__read_sector
; reset buffer pointer
- set [file_buffer_position], FILE_BUFFER_START + 1
+ set [file_buffer_position], MEM_FLOPPY_START + 1
set pc, pop
View
@@ -747,57 +747,63 @@
jsr postamble
;----------------------------------------------------------------
-; extern struct handle *int_pow(struct handle *factor1, struct handle *factor2)
+; extern struct handle *int_pow(struct handle *base, struct handle *exp)
;----------------------------------------------------------------
:int_pow
- set push, 2
- set push, 2
+ set push, 2 ; number of function arguments (base and exp)
+ set push, 2 ; number of heap handles
jsr preamble
- set push, [z+10]
+ set push, [z+10] ; sgn(exp)
jsr int_sgn
- ife x, 0
- set pc, int_pow_1
- ife x, -1
- set pc, int_pow_0
+ ife x, 0 ; exp = 0
+ set pc, int_pow_1 ; return 1
+ ife x, -1 ; base < 0
+ set pc, int_pow_0 ; return 0
- set push, [z+10]
+ set push, [z+10] ; exp to register (only support exp < 2**16)
jsr int_to_int16
- set c, x
+ set c, x ; c = (uint16) exp
- set [z+-1], [z+11] ; p
- set [z+-2], INT_HANDLE_1 ; r
+ set [z+-1], [z+11] ; p
+ set [z+-2], INT_HANDLE_1 ; r
:int_pow_loop
ife c, 0
set pc, int_pow_break
ifc c, 1
set pc, int_pow_skip
-
+
+ ; r = p * r
set push, [z+-2]
set push, [z+-1]
jsr int_mul
set [z+-2], x
:int_pow_skip
+ ; p = p * p
set push, [z+-1]
set push, [z+-1]
jsr int_mul
set [z+-1], x
+ ; c = c / 2
div c, 2
set pc, int_pow_loop
:int_pow_break
+ ; return r
set x, [z+-2]
set pc, postamble
:int_pow_0
+ ; return 0
set x, INT_HANDLE_0
set pc, postamble
:int_pow_1
+ ; return 1
set x, INT_HANDLE_1
set pc, postamble
View
@@ -182,7 +182,7 @@
set push, 0
jsr preamble
- set i, HEAP_START
+ set i, MEM_HEAP_START
set a, heap_handle_head ; struct handle *
sub a, HANDLE_NEXT
@@ -317,7 +317,7 @@
ifl x, [heap_handle_start]
set pc, pop
- ifg x, HEAP_END - SIZEOF_HANDLE
+ ifg x, MEM_HEAP_END - SIZEOF_HANDLE
set pc, pop
;---------------------------------------
View
@@ -39,7 +39,7 @@
; fastcall
;----------------------------------------------------------------
set x, [current_screen] ; struct screen *cur
- set x, [x + SCREEN_CURSOR]
+ set x, [x + SCREEN__CURSOR]
xor [x], 0xff80 ; change colors
set pc, pop
@@ -50,11 +50,11 @@
; y [sp+1]
;----------------------------------------------------------------
set x, [current_screen]
- set [x+SCREEN_CURSOR], [x+SCREEN_START]
+ set [x+SCREEN__CURSOR], [x+SCREEN__START]
mul [sp+1], SCREEN_COLS
- add [x+SCREEN_CURSOR], [sp+1]
- add [x+SCREEN_CURSOR], [sp+2]
+ add [x+SCREEN__CURSOR], [sp+1]
+ add [x+SCREEN__CURSOR], [sp+2]
set [sp], pop ; remove y
set [sp], pop ; remove x
@@ -69,10 +69,10 @@
set push, j
set a, [current_screen]
- set [a + SCREEN_CURSOR], [a + SCREEN_START]
+ set [a + SCREEN__CURSOR], [a + SCREEN__START]
- set i, [a + SCREEN_START]
- set a, [a + SCREEN_END]
+ set i, [a + SCREEN__START]
+ set a, [a + SCREEN__END]
:screen_clear_loop
set [i], 0
@@ -96,7 +96,7 @@
set push, j
set a, [current_screen]
- set i, [a + SCREEN_CURSOR]
+ set i, [a + SCREEN__CURSOR]
ife [c + lexer_table], lexer_char_newline
set pc, add_char_newline
@@ -113,25 +113,25 @@
add i, SCREEN_COLS
:add_char_scroll
- set [a + SCREEN_CURSOR], i
+ set [a + SCREEN__CURSOR], i
- ifl i, [a + SCREEN_END]
+ ifl i, [a + SCREEN__END]
set pc, add_char_finish
- sub [a + SCREEN_CURSOR], 32
+ sub [a + SCREEN__CURSOR], 32
- set i, [a + SCREEN_START]
- set j, [a + SCREEN_START]
+ set i, [a + SCREEN__START]
+ set j, [a + SCREEN__START]
add j, SCREEN_COLS
:add_char_copy
sti [i], [j]
- ifl j, [a + SCREEN_END]
+ ifl j, [a + SCREEN__END]
set pc, add_char_copy
:add_char_clear
sti [i], 0
- ifl i, [a + SCREEN_END]
+ ifl i, [a + SCREEN__END]
set pc, add_char_clear
:add_char_finish
@@ -142,8 +142,8 @@
set pc, pop
:add_char_backspace
- ifn i, [a + SCREEN_START]
+ ifn i, [a + SCREEN__START]
std [i+-1], 0
- set [a + SCREEN_CURSOR], i
+ set [a + SCREEN__CURSOR], i
set pc, add_char_finish
Oops, something went wrong.

0 comments on commit 853f7a5

Please sign in to comment.