Browse Source

Factored out string operations to procedures

refactor32
Jakob Kjær-Kammersgaard 5 years ago
parent
commit
d734e48a71
4 changed files with 84 additions and 54 deletions
  1. BIN
      IntToString.o
  2. +35
    -24
      Strings32.nasm
  3. +1
    -1
      build.sh
  4. +48
    -29
      go32bit.nasm

BIN
IntToString.o View File


+ 35
- 24
Strings32.nasm View File

@ -84,41 +84,52 @@ IntToString:
; IN: esi = base of string buffer
; IN: edx = justification width
; IN: ecx = string length
; IN: al = padding char
; ASSUMES: that the justification width > string length
; ASSUMES: that the size of the string buffer > justification width
RightJustifyString:
push esi
push edx
push ecx
push eax
pushad
pushfd
lea edi, [esi + edx-1]
lea esi, [esi + ecx-1]
lea esi, [esi + ecx] ; should include null terminator
lea edi, [esi + edx]
sub edx, ecx
std
sub edx, ecx ; edx should be difference
std ; Move string from the end
rep movsb ; |
mov ecx, edx
rep stosb ; Pad with AL
popfd
popad
ret
.copy_loop:
lodsb ; al = char
stosb
sub ecx, 1
jnz .copy_loop
; mov al, byte ' '
; .pad_loop:
; movsb
; sub edx, 1
; jnz .pad_loop
pushfd
pop eax
pop ecx
pop edx
pop esi
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copies ecx bytes
; IN: esi = source
; IN: edi = destination
; IN: ecx = number of bytes to copy
CopyData:
pushad
mov edx, ecx
and edx, 11b
shr ecx, 2
; ecx = quotient, edx = remainder
rep movsd
mov ecx, edx
rep movsb
popad
ret

+ 1
- 1
build.sh View File

@ -9,5 +9,5 @@ if [ "$1" != "run" ]; then
fi
if [ "$1" != "make" ]; then
qemu-system-x86_64.exe -drive index=0,format=raw,file=SingOS.img
qemu-system-x86_64 -drive index=0,format=raw,file=SingOS.img
fi

+ 48
- 29
go32bit.nasm View File

@ -250,12 +250,16 @@ ProtectedModeBaby:
mov fs, ax
mov gs, ax
; Setup stack
mov esp, 0x8000000
mov esp, (100 << 20) - 1 ; 100M Addressable
mov ebp, esp
; Space for dynamic variables
sub esp, 200*4 ; 200 32-bit integers
push ebp
DrawStuff:
xor ecx, ecx
@ -307,7 +311,7 @@ DrawStuff:
cmp edx, VIDEO_Y_RES-2
jne .DrawLoop
pop ebp
cld
@ -391,48 +395,53 @@ DrawStuff:
jmp .print_loop
.break_print_loop:
lea edi, [VIDEO + ScreenCoord(1, 24)]
mov ecx, 34
mov eax, 0
rep stosd
lea esi, [VarLabels]
lea edi, [ConversionBuffer]
mov ecx, VarLabelsLength
call CopyData
lea esi, [ConversionBuffer]
lea edi, [VIDEO + ScreenCoord(0, 24)]
mov ah, 0x0f
call PrintString
; lea esi, [ConversionBuffer]
mov eax, dword [Px]
sar eax, 4
call IntToString
push ecx
lea esi, [ConversionBuffer]
mov edx, 6
; lea esi, [ConversionBuffer]
; ecx set by IntToString
mov edx, 7
mov al, ' '
call RightJustifyString
lea edi, [VIDEO + ScreenCoord(1, 24)]
mov ah, 0x0f
; esi still ConversionBuffer
mov ecx, edx
lea edi, [VIDEO + ScreenCoord(StrXStart, 24)]
mov ah, 0x70
call PrintString
lea esi, [ConversionBuffer]
pop eax
; lea esi, [ConversionBuffer]
mov eax, dword [Py]
sar eax, 4
call IntToString
lea esi, [ConversionBuffer]
lea edi, [VIDEO + ScreenCoord(40, 24)]
mov ah, 0x0f
call PrintString
; lea esi, [ConversionBuffer]
; ecx set by IntToString
mov edx, 7
mov al, ' '
call RightJustifyString
; esi still ConversionBuffer
mov ecx, edx
lea edi, [VIDEO + ScreenCoord(StrYStart, 24)]
mov ah, 0x70
call PrintString
; add edi, 12*2
; mov eax, dword [Py]
; sar eax, 4
; call IntToString
; add edi, 12*2
; mov eax, [Zoom]
; sar eax, 9
; call IntToString
add [ColorOffset], dword 1
@ -462,7 +471,17 @@ Reboot:
;;;;;;;;;;;;;;;;;;;;;;;;
;; Strings
;;;;;;;;;;;;;;;;;;;;;;;;
VarLabels: db "X:"
StrXStart equ $-VarLabels
db " "
db "Y:"
StrYStart equ $-VarLabels
db " "
VarLabelsLength equ $-VarLabels
ProtectedWelcomeStr: db " Placeholder for SingOS - 32 bit edition! ", 0
ProtectedWelcomeStrLength equ $-ProtectedWelcomeStr
TestStr: db "hello, world"
TestStrLength equ $-TestStr
ThereWasSomethingStr: db " KEY = '"
Key: db " ' ", 0
Px: dd 0

Loading…
Cancel
Save