1 ;; Ketmar's common utility functions
3 ;; Copyright (C) 2020 Ketmar Dark // Invisible Vector
5 ;; This program is free software: you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation, version 3 of the License ONLY.
9 ;; This program is distributed in the hope that it will be useful,
10 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;; GNU General Public License for more details.
14 ;; You should have received a copy of the GNU General Public License
15 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ccf fix cmc ; complement carry
22 scf fix stc ; set carry
72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
73 ;; display n as hex number, in compile-time
79 d = "0" + n shr (bits-%*4) and 0Fh
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 ;; display n as unsigned decimal number, in compile-time
92 local cnt,divisor,still,d,nn
93 ; this can be done recursive, but...
107 ; cnt -- number of digits
108 ; divisor -- guess what
118 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119 ;; convert low 4 bits of AL to hex digit ready to print
121 ;; out: AL: hex digit ready to print (uppercased)
122 ;; it's voodoo %-) can somebody explain this code? %-)
123 ;; heh, it's one byte shorter than the common snippets i've seen
124 ;; many times in teh internets.
125 ;; actually,, this is the code from my Z80 library. %-)
130 das ; yeah, yeah, das ist fantastich!
134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
135 ;; display asciiz string at the given address, in compile time
137 macro display_asciiz_at addr {
141 load chr byte from addr
152 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
178 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
182 macro elf_hash_str str* {
183 local bpos,hash,high,xstr,b
188 load b byte from xstr+bpos
190 hash = ((hash shl 4)+b) and 0xffffffff
191 high = hash and 0xf0000000
192 hash = hash xor (high shr 24)
193 hash = hash and (high xor 0xffffffff)
195 load b byte from xstr+bpos
198 elf_hash_value = hash
203 assert elf_hash_value = 0x00000061
205 assert elf_hash_value = 0x00000672
206 elf_hash_str "The quick brown fox jumps over the lazy dog"
207 assert elf_hash_value = 0x04280C57