Skip to content

Commit

Permalink
fix(templates): avoid clobbering ebx in su_load_gmdls
Browse files Browse the repository at this point in the history
Fixes #130
  • Loading branch information
vsariola committed Feb 16, 2024
1 parent c08a319 commit 6d3c65e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Dbgain unit, which allows defining the gain in decibels (-40 dB to +40dB)

### Fixed
- 32-bit su_load_gmdls clobbered ebx, even though __stdcall demands it to be not
touched

## v0.3.0
### Added
- Scroll bars to menus, shown when a menu is too long to fit.
Expand Down
16 changes: 9 additions & 7 deletions vm/compiler/templates/amd64-386/gmdls.asm
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@
add rsp, 40 ; shadow space, as required by Win64 ABI
ret
{{else}}
mov ebx, su_sample_table
push 0 ; OF_READ
push ebx ; &ofstruct, blatantly reuse the sample table
push su_gmdls_path1 ; path
call dword [__imp__OpenFile@12]; eax = OpenFile(path,&ofstruct,OF_READ) // should not touch ebx according to calling convention
mov eax, su_sample_table
; these are the arguments for ReadFile
push 0 ; NULL
push ebx ; &bytes_read, reusing sample table again; it does not matter that the first four bytes are trashed
push eax ; &bytes_read, reusing sample table again; it does not matter that the first four bytes are trashed
push 3440660 ; number of bytes to read
push ebx ; here we actually pass the sample table to readfile
push eax ; here we actually pass the sample table to readfile
; these are for OpenFile
push 0 ; OF_READ
push eax ; &ofstruct, blatantly reuse the sample table
push su_gmdls_path1 ; path
call dword [__imp__OpenFile@12]; eax = OpenFile(path,&ofstruct,OF_READ)
push eax ; handle to file
call dword [__imp__ReadFile@20] ; Readfile(handle,&su_sample_table,SAMPLE_TABLE_SIZE,&bytes_read,NULL)
ret
Expand Down

0 comments on commit 6d3c65e

Please sign in to comment.