A combined N-body/hydrodynamical code is presented. Hydrodynamical properties are determined using smoothed particle hydrodynamics (SPH). The gravitational interaction of gas and collisionless particles is treated in a direct summation approach which benefits from the high speed of the special-purpose hardware GRAPE (GRAvity PipE). Besides gravitational forces, GRAPE also returns the list of neighbours, and can therefore be used to speed up the hydrodynamical part also. After the interaction list has been passed, density, pressure forces, propagation and interpolation of particles, etc., are calculated on the frontend, a 50-MHz SUN SPARC 10. In order to combine SPH and GRAPE, possible limitations arising from the hardware design of GRAPE are carefully analysed and modifications compared with current SPH codes are discussed. The resulting code, GRAPESPH, is Of Similar flexibility to TREESPH. 50-55 per cent of the CPU time is spent in calculating the densities and the pressure forces on the front end, 15-20 per cent in calculating gravity, and about 10 per cent in miscellaneous subroutines. Another 20 per cent is required by communication, mainly to read out the neighbour list via the VME interface. The main shortcoming is the inflexible, hardwired force law (a Plummer law), which makes it difficult to include periodic boundary conditions. Also, because of the limited dynamic range, GRAPESPH seems to be less suitable to perform large-scale structure simulations, where the resolution should be high everywhere in the simulation volume. The resulting code seems, however, especially well suited to investigate the formation of individual objects in a large-scale structure environment, such as, for example, galaxies or clusters. Such simulations require a very high spatial resolution, but only within a relatively small subvolume. By means of a multiple-time-step scheme, time-step constraints arising from local stability criteria can almost be avoided. The total performance is at least half as good as that of TREESPH On a GRAY, and for most applications it seems to be even better. The CPU time per time-step is only slightly dependent on the clustering state. GRAPESPH therefore provides a very attractive alternative to the use of supercomputers in cosmology.