From d734e48a7188cffe926b241a356021e48023fe76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Kj=C3=A6r-Kammersgaard?= Date: Wed, 21 Nov 2018 23:39:00 +0100 Subject: [PATCH] Factored out string operations to procedures --- IntToString.o | Bin 992 -> 0 bytes Strings32.nasm | 59 ++++++++++++++++++++++--------------- build.sh | 2 +- go32bit.nasm | 77 ++++++++++++++++++++++++++++++------------------- 4 files changed, 84 insertions(+), 54 deletions(-) delete mode 100644 IntToString.o diff --git a/IntToString.o b/IntToString.o deleted file mode 100644 index ff4c2b058c2f6e591501ed7805008e3bfee23a88..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 992 zcmb<-^>JflWMqH=Mh0dE1doBi0V-hvrZpJYf%4=4keMLN2GyJZQ6f022d)Ayf`Tfy@8_aUcdt!9f6!^8m~Fy%$d%E&4(GkKR@`2 zxtC`W<4MgE%?AuRy#IGzXuVYW*z#Vn82>gl{%yiQ4b86^JHq~VI5S#)E`Jpf9T$H% zBQ>iykqc-#u|TgRwW5SUFD0=gkwLFGqqwA~Bryrds?3GZP<~Nr4n!pZb7A2IQpUpY z@jtS1)RYDae{KLv4v<}q#BYMLK@28_HXsR# z0too{zaPjz@R=B<0r?tGSq7kch2U&ZJOh2>nO72$A6!zDnU}7Ymsp(35MNx9SX6>6 zj?C7}%P)z~OHEHK$t+7nkx0ob%S=g)&&kg(KoKu4Pb|P9nw?n?50YZYEly|1NiWHW b2QiXL)6!Cl7;;kcpzZ|ug%Ox0#h^3*J`I&; diff --git a/Strings32.nasm b/Strings32.nasm index b61132a..3fefd94 100644 --- a/Strings32.nasm +++ b/Strings32.nasm @@ -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 + diff --git a/build.sh b/build.sh index 90c5716..884d0f4 100644 --- a/build.sh +++ b/build.sh @@ -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 diff --git a/go32bit.nasm b/go32bit.nasm index bbf13a4..c3b6a78 100644 --- a/go32bit.nasm +++ b/go32bit.nasm @@ -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