locals: cosmetix
[urforth.git] / level0 / urforth_dprint.asm
blob4b4218174e8dc42ba20f4947accd25a9b3cad87f
1 ;; Native x86 GNU/Linux Forth System, Direct Threaded Code
2 ;; utilities
3 ;;
4 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
5 ;;
6 ;; This program is free software: you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation, version 3 of the License ONLY.
9 ;;
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 macro save_all_registers {
19 pushad
20 pushfd
23 macro restore_all_registers {
24 popfd
25 popad
29 macro dprint [str] {
30 common
31 local nstart
32 local nend
33 jmp nend
34 nstart = $
35 forward
36 db str
37 common
38 nend = $
40 save_all_registers
41 mov eax,4
42 mov ebx,2
43 mov ecx,nstart
44 mov edx,nend-nstart
45 syscall
46 restore_all_registers
49 macro dprint_char_al {
50 save_all_registers
51 push eax
52 mov eax,4
53 mov ebx,2
54 mov ecx,esp
55 mov edx,1
56 syscall
57 pop eax
58 restore_all_registers
61 macro dprint_char chr {
62 if chr eq al
63 dprint_char_al
64 else
65 push eax
66 mov al,chr
67 dprint_char_al
68 pop eax
69 end if
72 macro dprint_cr {
73 dprint_char 10
76 macro dprint_hex_al {
77 save_all_registers
78 mov cl,al
79 shr al,4
80 Nibble2Hex
81 dprint_char_al
82 mov al,cl
83 Nibble2Hex
84 dprint_char_al
85 restore_all_registers
88 macro dprint_hex_eax {
89 local xloop
90 save_all_registers
91 mov ecx,4
92 xloop:
93 rol eax,8
94 dprint_hex_al
95 loop xloop
96 restore_all_registers
99 macro dprint_hex reg {
100 if reg eq eax
101 dprint_hex_eax
102 else
103 push eax
104 mov eax,reg
105 dprint_hex_eax
106 pop eax
107 end if
110 macro dprint_strz_esi {
111 local shit,shitex
112 push esi
113 push eax
114 pushfd
116 shit:
117 lodsb
118 or al,al
119 jr z,shitex
120 dprint_char_al
121 jr shit
122 shitex:
123 popfd
124 pop eax
125 pop esi
128 macro dprint_strz_at reg {
129 if reg eq esi
130 dprint_strz_esi
131 else
132 push esi
133 mov esi,reg
134 dprint_strz_esi
135 pop esi
136 end if