diff options
author | Javier <dev.git@javispedro.com> | 2022-04-03 22:58:39 +0200 |
---|---|---|
committer | Javier <dev.git@javispedro.com> | 2022-04-03 22:58:39 +0200 |
commit | f9b0699da8adb44fd91640180a7b70639a43449b (patch) | |
tree | 81fcbd285a306b85f21086d1c7d37e77af71ed12 | |
parent | 71f66c759930ce22f099ad1631f05ddb3e0ccd8a (diff) | |
download | vbados-f9b0699da8adb44fd91640180a7b70639a43449b.tar.gz vbados-f9b0699da8adb44fd91640180a7b70639a43449b.zip |
replace some custom asm utils with watcom intrinsincs
-rw-r--r-- | dostsr.c | 20 | ||||
-rw-r--r-- | makefile | 9 | ||||
-rw-r--r-- | utils.h | 55 | ||||
-rw-r--r-- | vbox.h | 9 | ||||
-rw-r--r-- | vboxlog.h | 12 | ||||
-rw-r--r-- | w16mouse.c | 7 |
6 files changed, 31 insertions, 81 deletions
@@ -17,6 +17,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <stdlib.h> +#include <string.h> #include <i86.h> #include "dlog.h" @@ -186,7 +188,7 @@ static void hide_graphic_cursor(void) plane, y); // Restore this scaline from cursor_prev - nfmemcpy(line, prev, cursor_bytes_per_line); + _fmemcpy(line, prev, cursor_bytes_per_line); } } @@ -230,7 +232,7 @@ static void show_graphic_cursor(void) unsigned x; // First, backup this scanline to prev before any changes - fnmemcpy(prev, line, cursor_bytes_per_line); + _fmemcpy(prev, line, cursor_bytes_per_line); // when start.x is not pixel aligned, // scaline points the previous multiple of pixels_per_byte; @@ -380,7 +382,7 @@ static void load_cursor(void) uint8_t *output = req->pointerData; unsigned int y, x; - bzero(req, sizeof(VMMDevReqMousePointer)); + memset(req, 0, sizeof(VMMDevReqMousePointer)); req->header.size = vbox_req_mouse_pointer_size(width, height); req->header.version = VMMDEV_REQUEST_HEADER_VERSION; @@ -555,7 +557,7 @@ static void handle_mouse_event(uint16_t buttons, bool absolute, int x, int y, in } else if (x || y) { // Relative movement: x,y are in mickeys uint16_t ticks = bda_get_tick_count_lo(); - unsigned ax = ABS(x), ay = ABS(y); + unsigned ax = abs(x), ay = abs(y); events |= INT33_EVENT_MASK_MOVEMENT; @@ -733,7 +735,7 @@ static void reset_mouse_settings() data.cursor_text_xor_mask = 0x7700U; data.cursor_hotspot.x = 0; data.cursor_hotspot.y = 0; - nnmemcpy(data.cursor_graphic, default_cursor_graphic, sizeof(data.cursor_graphic)); + memcpy(data.cursor_graphic, default_cursor_graphic, sizeof(data.cursor_graphic)); refresh_cursor(); // This will hide the cursor and update data.cursor_visible } @@ -764,7 +766,7 @@ static void reset_mouse_state() data.cursor_pos.x = 0; data.cursor_pos.y = 0; data.cursor_prev_char = 0; - bzero(data.cursor_prev_graphic, sizeof(data.cursor_prev_graphic)); + memset(data.cursor_prev_graphic, 0, sizeof(data.cursor_prev_graphic)); } static void return_clear_wheel_counter(union INTPACK __far *r) @@ -884,7 +886,7 @@ static void int33_handler(union INTPACK r) hide_cursor(); data.cursor_hotspot.x = r.x.bx; data.cursor_hotspot.y = r.x.cx; - fnmemcpy(data.cursor_graphic, MK_FP(r.x.es, r.x.dx), sizeof(data.cursor_graphic)); + _fmemcpy(data.cursor_graphic, MK_FP(r.x.es, r.x.dx), sizeof(data.cursor_graphic)); load_cursor(); refresh_cursor(); break; @@ -944,11 +946,11 @@ static void int33_handler(union INTPACK r) break; case INT33_SAVE_MOUSE_STATUS: dlog_puts("Mouse save status"); - nfmemcpy(MK_FP(r.x.es, r.x.dx), &data, sizeof(TSRDATA)); + _fmemcpy(MK_FP(r.x.es, r.x.dx), &data, sizeof(TSRDATA)); break; case INT33_LOAD_MOUSE_STATUS: dlog_puts("Mouse load status"); - fnmemcpy(&data, MK_FP(r.x.es, r.x.dx), sizeof(TSRDATA)); + _fmemcpy(&data, MK_FP(r.x.es, r.x.dx), sizeof(TSRDATA)); break; case INT33_SET_MOUSE_SENSITIVITY: dlog_print("Mouse set speed x="); @@ -2,15 +2,16 @@ # Assuming you have sourced `owsetenv` beforehand. # dosobjs = dostsr.obj dosmain.obj vbox.obj -doscflags = -bt=dos -ms -6 -os -w3 +doscflags = -bt=dos -ms -6 -os -oi -w3 # -ms to use small memory model (though sometimes ss != ds...) # -os to optimize for size +# -oi to put intrinsics online (don't use them much) dostsrcflags = -zu -s -g=RES_GROUP -nd=RES -nt=RES_TEXT -nc=RES_CODE # -s to disable stack checks, since it inserts calls to the runtime from the TSR part # -zu since ss != ds on the TSR w16objs = w16mouse.obj -w16cflags = -bt=windows -bd -mc -zu -s -6 -w3 +w16cflags = -bt=windows -bd -mc -zu -s -6 -oi -w3 # -bd to build DLL # -mc to use compact memory model (far data pointers, ss != ds always) # -zu for DLL calling convention (ss != ds) @@ -46,6 +47,6 @@ vbmouse.flp: mformat -C -f 1440 -v VBMOUSE -i $^@ :: # Build a floppy image containing the driver -flp: vbmouse.flp vbmouse.exe vbmouse.drv .SYMBOLIC - mcopy -i vbmouse.flp -o vbmouse.exe vbmouse.drv :: +flp: vbmouse.flp vbmouse.exe vbmouse.drv oemsetup.inf .SYMBOLIC + mcopy -i vbmouse.flp -o vbmouse.exe vbmouse.drv oemsetup.inf :: @@ -3,8 +3,6 @@ #include <stdint.h> -#define ABS(x) (((x) < 0) ? -(x) : (x)) - #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #define MAX(a,b) (((a) > (b)) ? (a) : (b)) @@ -13,12 +11,6 @@ static inline void breakpoint(void); #pragma aux breakpoint = 0xcd 0x03; -static inline void cli(void); -#pragma aux cli = "cli" - -static inline void sti(void); -#pragma aux sti = "sti" - /** Map x linearly from range [0, srcmax] to [0, dstmax]. * Equivalent of (x * dstmax) / srcmax but with 32-bit unsigned precision. */ static unsigned scaleu(unsigned x, unsigned srcmax, unsigned dstmax); @@ -59,51 +51,4 @@ static int scalei_rem(int x, int srcmax, int dstmax, short *rem); __value [ax] \ __modify [ax cx dx si] -static void bzero(void __far *buf, unsigned int size); -#pragma aux bzero = \ - "cld" \ - "mov ax, 0" \ - "rep stos byte ptr es:[di]" \ - __parm [es di] [cx] \ - __modify [ax] - -static void nfmemcpy(void __far *dst, const void *src, unsigned int size); -#pragma aux nfmemcpy = \ - "cld" \ - "rep movs byte ptr es:[di], byte ptr ds:[si]" \ - __parm [es di] [si] [cx] \ - __modify [cx si di] - -static void fnmemcpy(void *dst, const void __far *src, unsigned int size); -#pragma aux fnmemcpy = \ - "cld" \ - "push gs" \ - "mov ax, es" \ - "mov gs, ax" /* gs is now the src segment */ \ - "mov ax, ds" \ - "mov es, ax" /* es is now ds, the dst segment */ \ - "rep movs byte ptr es:[di], byte ptr gs:[si]" \ - "pop gs" \ - __parm [di] [es si] [cx] \ - __modify [ax cx si di es] - -static void ffmemcpy(void __far *dst, const void __far *src, unsigned int size); -#pragma aux ffmemcpy = \ - "cld" \ - "push gs" \ - "mov gs, ax" \ - "rep movs byte ptr es:[di], byte ptr gs:[si]" \ - "pop gs" \ - __parm [es di] [gs si] [cx] \ - __modify [cx si di] - -static void nnmemcpy(void *dst, const void *src, unsigned int size); -#pragma aux nnmemcpy = \ - "cld" \ - "mov ax, ds" \ - "mov es, ax" /* es is now ds, the src+dst segment */ \ - "rep movs byte ptr es:[di], byte ptr ds:[si]" \ - __parm [di] [si] [cx] \ - __modify [cx si di es] - #endif @@ -22,6 +22,7 @@ #include <stdbool.h> #include <stdint.h> +#include <string.h> #include "dlog.h" #include "vds.h" @@ -69,7 +70,7 @@ static int vbox_report_guest_info(LPVBOXCOMM vb, uint32_t osType) { VMMDevReportGuestInfo __far *req = (void __far *) vb->buf; - bzero(req, sizeof(VMMDevReportGuestInfo)); + _fmemset(req, 0, sizeof(VMMDevReportGuestInfo)); req->header.size = sizeof(VMMDevReportGuestInfo); req->header.version = VMMDEV_REQUEST_HEADER_VERSION; @@ -88,7 +89,7 @@ static int vbox_set_mouse(LPVBOXCOMM vb, bool absolute, bool pointer) { VMMDevReqMouseStatus __far *req = (void __far *) vb->buf; - bzero(req, sizeof(VMMDevReqMouseStatus)); + _fmemset(req, 0, sizeof(VMMDevReqMouseStatus)); req->header.size = sizeof(VMMDevReqMouseStatus); req->header.version = VMMDEV_REQUEST_HEADER_VERSION; @@ -110,7 +111,7 @@ static int vbox_get_mouse(LPVBOXCOMM vb, bool __far *abs, { VMMDevReqMouseStatus __far *req = (void __far *) vb->buf; - bzero(req, sizeof(VMMDevReqMouseStatus)); + _fmemset(req, 0, sizeof(VMMDevReqMouseStatus)); req->header.size = sizeof(VMMDevReqMouseStatus); req->header.version = VMMDEV_REQUEST_HEADER_VERSION; @@ -131,7 +132,7 @@ static int vbox_set_pointer_visible(LPVBOXCOMM vb, bool visible) { VMMDevReqMousePointer __far *req = (void __far *) vb->buf; - bzero(req, sizeof(VMMDevReqMousePointer)); + _fmemset(req, 0, sizeof(VMMDevReqMousePointer)); req->header.size = sizeof(VMMDevReqMousePointer); req->header.version = VMMDEV_REQUEST_HEADER_VERSION; @@ -1,12 +1,12 @@ #ifndef VBOXDLOG_H #define VBOXDLOG_H +#include <conio.h> + /** Logs a single character to the VBox debug message port. */ -static void vbox_log_putc(char c); -#pragma aux vbox_log_putc = \ - "mov dx, 0x504" \ - "out dx, al" \ - __parm [al] \ - __modify [dx] +static inline void vbox_log_putc(char c) +{ + outp(0x504, c); +} #endif // VBOXDLOG_H @@ -124,7 +124,8 @@ BOOL FAR PASCAL LibMain(HINSTANCE hInstance, WORD wDataSegment, uint16_t version = int33_get_driver_version(); // For now we just check for the presence of any int33 driver version - if (version <= 0) { + if (version == 0) { + // No one responded to our request, we can assume no driver // This will cause a "can't load .drv" message from Windows return 0; } @@ -147,9 +148,9 @@ WORD FAR PASCAL Inquire(LPMOUSEINFO lpMouseInfo) VOID FAR PASCAL Enable(LPFN_MOUSEEVENT lpEventProc) { // Store the windows-given callback - cli(); // Write to far pointer may not be atomic, and we could be interrupted mid-write + _disable(); // Write to far pointer may not be atomic, and we could be interrupted mid-write eventproc = lpEventProc; - sti(); + _enable(); if (!enabled) { int33_reset(); |